当我通过 Phonegap 加载 Web 应用程序并发出 Web 请求(通过 AJAX 或其他方式)时,根本不会设置 REFERRER HTTP header 。这会干扰某些第三方网站的功能。如何发送 REFERRER header ?
(我使用的是Phonegap 3.5.0-0.20.10)
最佳答案
正如 @JamesWong 所说,现在有一个名为 cordovaHttp 的插件适用于所有平台。
您可以使用 cordova plugin add https://github.com/wymsee/cordova-HTTP.git
命令添加该插件,然后您可以添加任何 http header ,如下所示。
cordovaHTTP.post("https://google.com/, {
id: 12,
message: "test"
}, { Authorization: "OAuth2: token" }, function(response) {
// prints 200
console.log(response.status);
try {
response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error("JSON parsing error");
}
}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
关于cordova - Web 请求中未设置 Referrer header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25111043/