gpt4 book ai didi

javascript - Chrome WebAPIchrome.webRequest.onBeforeSendHeaders 不更改传出请求中的参数

转载 作者:行者123 更新时间:2023-11-28 00:22:56 24 4
gpt4 key购买 nike

我尝试将 IP 添加到 requestHeader 中的 X-Forwarded-For 参数,但我的 Chrome API 示例代码并未执行此操作。

我有以下代码:

var requestFilter = {
urls: [ "<all_urls>" ]
},

extraInfoSpec = ['requestHeaders', 'blocking'],

handler = function( details ) {

var headers = details.requestHeaders,
blockingResponse = {};

var isXForwardedForSet = false;

for (var i = 0, l = headers.length; i < l; ++i) {
if (headers[i].name === 'X-Forwarded-For') {
headers[i].value = "42.104.0.0";
isXForwardedForSet = true;
break;
}
}

if (!isXForwardedForSet) {
headers.push({
name: "X-Forwarded-For",
value: "42.104.0.0"
});
}

blockingResponse.requestHeaders = headers;

return blockingResponse;

};

chrome.webRequest.onBeforeSendHeaders.addListener( handler, requestFilter, extraInfoSpec );

最佳答案

与代理相关的 header 可能会被忽略。

引用docs :

Note that the web request API presents an abstraction of the network stack to the extension. Internally, one URL request can be split into several HTTP requests (for example to fetch individual byte ranges from a large file) or can be handled by the network stack without communicating with the network. For this reason, the API does not provide the final HTTP headers that are sent to the network. For example, all headers that are related to caching are invisible to the extension.

没有被忽略的 header 的完整列表,但文档中列出了一些 header 。常识性标准:如果它代表有关网络的知识(缓存、代理等),则 API 无法触及它。

关于javascript - Chrome WebAPIchrome.webRequest.onBeforeSendHeaders 不更改传出请求中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29809200/

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