cordova - Web 请求中未设置 Referrer header

标签 cordova xmlhttprequest referrer

当我通过 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);
});

来源:https://github.com/wymsee/cordova-HTTP

关于cordova - Web 请求中未设置 Referrer header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25111043/

相关文章:

javascript - 使用 phonegap 和 android 的 javascript 警报中的特殊字符

javascript - iOS chrome - 翻译页面时 xhr.timeout 抛出错误

ios - 让网站知道它们是从 iOS App 内的 WebView 访问的

facebook - 如何跟踪 Facebook iframe 应用程序的流量来源

javascript - Cordova 对话框插件 : insert HTML tags in notification. 警报消息

ios - Phonegap/Cordova 2.0 - 不在应用程序内填充

android - Ionic - 错误 : Failed to fetch plugin cordova-plugin-statusbar@https://github. com/apache/cordova-plugin-statusbar.git 通过注册表

javascript - 无法在 IE10 中使用 XmlHttpRequest 加载 Blob

google-chrome - XMLHttpRequest 使用用户名/密码发送 GET HTTP 请求

php - 我如何知道正在用 PHP 加载脚本的页面的 URL?