我需要在GET方法中调用一个服务,传递2个参数和一个特定的Atuhorization标题。
问题是如果我在GET中传递params,该服务会在预检模式下给我一个OPTION错误。
错误标题选项示例:
var token = 'fvvrgbrberb';
var settings = {
"async": true,
"crossDomain": true,
"processData" : false,
"url": "https://domain.ld/page/?param1=109¶m2=598c37ab2b951",
"method": "GET",
"headers": {
"authorization": "Bearer "+token,
}
}
$.ajax(settings).done(function (response) {
console.info('Done: ',response);
}).fail(function(response){
console.info('error: ',response);
});
没有错误的示例:
var token = 'fvvrgbrberb';
var settings = {
"async": true,
"crossDomain": true,
"processData" : false,
"url": "https://domain.ld/page/",
"method": "GET",
"headers": {
"authorization": "Bearer "+token,
}
}
$.ajax(settings).done(function (response) {
console.info('Done: ',response);
}).fail(function(response){
console.info('error: ',response);
});
所以,如果我不在GET模式下发送params,那就好了,否则我得到了错误。
更详情
在ex 2中,当我调用service时,获取带有期望结果的json {data:{some data}},在ex 1中我给出了json错误(由我设置)因为服务找不到HTTP_AUTHORIZATION头在请求中。我从POSTMAN复制了代码,并且在这两种情况下都没有问题。希望这有帮助!
我的目标是,如果在HTTP_AUTHORIZATION中有一个有效的tocken,我需要下载一个文件。
更多信息:
如果我使用 php cUrl 而不是jQuery Ajax来进行调用,则找不到错误!
希望这有帮助!