当我的应用POST
请求其工作时。看起来像
http://192.168.0.165:3000/proxy/http%3A%2F%2Fhomestead.app%2Fapi%2Fv1%2Fuser%2F
但是,当我使用GET
做下一个请求时,这个请求无效。
我认为是因为我的params
发送的内容丢失了。我如何在phonegap中修复它或禁用代理?
答案 0 :(得分:4)
在index.html
文件
(function() {
var xhr = {};
xhr.open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
console.log(url);
if(url.indexOf('/proxy/') == 0){
url = window.decodeURIComponent(url.substr(7));
}
xhr.open.apply(this, arguments);
};
})(window);
如果您开始面对“Access-Control-Allow-Origin”问题,请使用此扩展程序进行chrome(modheader)并添加如下响应:
Access-Control-Allow-Origin:http://yourip:3000
如果您要发出多个请求并希望在它们之间共享会话,请添加另一个响应,如下所示:
Access-Control-Allow-Credentials: true