[英]can any one tell me how can i remove preflight request from this $http header
//individual logins
$rootScope.setting.instances.forEach(function(ins) {
var header = {
"Accept": "application/json",
"Authorization": "Basic " + btoa( ins.uname + ':' + ins.pword ),
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "GET, POST, DELETE, PUT, JSONP"
};
$http({ method : 'post', url : ins.url, headers: header })
.success( function( data )
{
console.log( ins.name +" login success" );
$("#fail" + ins.id ).hide();
$("#succ" + ins.id ).show();
//logins : a global variable declared in app.js
logins.push('{"ins" : '+ ins.id + ',"isAvailable" : "true"}');
checkFinished();
})
.error( function( data)
{
console.log( ins.name +" login failed" );
$("#fail" + ins.id ).show();
$("#succ" + ins.id ).hide();
//logins : a global variable declared in app.js
logins.push('{"ins" : '+ ins.id + ',"isAvailable" : "false"}');
checkFinished();
});
});
}
The CORS specification requires a browser to preflight the request with the OPTIONS request if any custom headers are specified on the cross origin request. 如果在跨源请求上指定了任何自定义标头,则CORS规范要求浏览器将请求与OPTIONS请求一起进行预检。 And, when it does the OPTIONS preflight, it does not include your custom headers because part of what the OPTIONS request is for is to find out what custom headers are allowed to be sent on the request.
而且,当它执行OPTIONS预检时,它不包括您的自定义标头,因为OPTIONS请求的目的是找出允许在请求上发送哪些自定义标头。 So, a server is not supposed to require custom headers on the OPTIONS request if it wants this to work from a browser.
因此,如果服务器希望它可以通过浏览器运行,则不应在OPTIONS请求上要求自定义标头。
So, if you don't want it to preflight with the OPTIONS request, then you have to not use custom headers on the request. 因此,如果您不希望它与OPTIONS请求一起进行预检,则不必在请求中使用自定义标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.