AngularJS - 如何禁用选项要求? [英] AngularJS - how to disable OPTION request?
问题描述
我发现我的角度是创造OPTIONS请求也各POST请求之前。
I noticed that my Angular is creating OPTIONS request also before each POST request.
我使用自定义的API服务的HTTP请求处理。
I'm using custom API Service for HTTP request handling.
app.service('ApiService', function ($http) {
/**
* Process remote POST request to give URL with given params
* @param {String} url
* @param {String} POST params
* @return {JSON} response from server
*/
this.doHttpRequest = function (type, url, params) {
return $http({
method: type,
url: url,
data: params,
timeout: 5000,
headers: {
"Content-Type": "application/json",
}
});
}
});
的问题是:
如何禁用它(这配置值放到哪里)?
How can i disable it (which config values put where)?
时的选项好东西吗?
我认为这是它像2服务器之间的握手。
Is OPTIONS good for something? I think that is it something like "Handshake between 2 servers".
角版本:1.2.15
感谢您的任何意见。
推荐答案
这是没有棱角。这是XMLHtt prequest。
That isn't Angular. It is XMLHttpRequest.
复杂跨域的HTTP请求需要一个pre-飞行OPTIONS请求使浏览器可以找出其他的服务器将权限授予Ajax请求。
Complex cross-origin HTTP requests require a pre-flight OPTIONS request so the browser can find out if the other server will grant permission for the Ajax request.
使得短确保你正在Ajax请求是<一个href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests\">simple,有没有办法为prevent OPTIONS请求。
Short of making sure the Ajax request you are making is simple, there is no way to prevent the OPTIONS request.
一个简单的要求:
- 只有使用GET,HEAD或POST。如果POST用于将数据发送到服务器,发送到与HTTP POST请求的服务器中的数据的内容类型是应用程序的一个/ X WWW的形式,urlen codeD,多部分/形式数据,或者text / plain的。
- 不设置自定义标题(如X-修改等)
与HTTP请求
除非你愿意放弃发送JSON,你不能用一个简单的要求这一点。
Unless you wish to give up sending JSON, you can't use a simple request for this.
这篇关于AngularJS - 如何禁用选项要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!