gpt4 book ai didi

angularjs - 使用 $resource 发送 ETag

转载 作者:行者123 更新时间:2023-12-04 20:06:30 25 4
gpt4 key购买 nike

使用 Angular JS 的 $resource 服务,有没有办法为资源的第二次、第三次等轮询指定 If-None-Match 和 ETag header ?

    var SummarySearch = $resource(<<apiurl>>,
{ },
{
get: {
method: 'GET',
headers: {
'x-header': 'id'
}
}
});

我已经使用它来设置一个常量 header (在这种情况下它只是 x-header: id),但是我需要根据我上次看到的 ETag 每个请求不同的东西。

更新:
transformRequest看起来很有希望,但我无权访问我发起请求的数据,或该数据结束的 URL。据我所知,我只能访问我要发布的正文(在我的情况下未定义,因为我正在执行 GET)和 headersGetter 函数。

最佳答案

我发现 $resource 自己处理 ETag。

当我发布这个问题时,我还没有实现服务器端的东西。我设置了 If-None-Match 处理服务器端,我认为我只需要在客户端上使用 $http 服务,但是使用我现有的 $resource .get 调用进行了尝试,它可以处理设置 If-None-Match在我第一次轮询资源后自动 header 。

我正在重用 $resource 在安装过程中返回的 1 个实例。

编辑

而且我有真正的 jQuery 而不是 jqLit​​e。这就是 If-None-Match 似乎被设置的地方。

    // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
ifModifiedKey = ifModifiedKey || s.url;
if ( jQuery.lastModified[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
}
if ( jQuery.etag[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
}
}

关于angularjs - 使用 $resource 发送 ETag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24987957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com