作者:手机用户2502941011 | 来源:互联网 | 2023-05-18 18:38
ImusingAngular1.4.8togetdatafromRESTfullAPI.Foruserauthenticationwedecidedtousecus
I'm using Angular 1.4.8 to get data from RESTfull API. For user authentication we decided to use custom HTTP header:
我正在使用Angular 1.4.8从RESTfull API获取数据。对于用户身份验证,我们决定使用自定义HTTP标头:
var requestCOnfig= {
headers: {
"authorization-token": "A317C3D6-74B1-DA99-FE55-8141E95D3085"
}
};
Now, I'm trying to make a GET request:
现在,我正在尝试发出GET请求:
$http.get(config.apiUrl+'/api/v1/orders/', requestConfig).success(function(data){
table.orders = data;
});
And see the following requests in Firebug:
并在Firebug中查看以下请求:
I read that browsers make these pre-flight OPTIONS request if you trying to get data from another server. In my case Angular application is on 127.0.0.1:80 and Node.js server is on 127.0.0.1:6673, so it's cross-origin request as I understand
我读过如果你试图从另一台服务器获取数据,浏览器会发出这些飞行前的OPTIONS请求。在我的情况下,Angular应用程序在127.0.0.1:80上,而Node.js服务器在127.0.0.1:6673上,所以它是跨源请求,据我所知
If you try to make OPTIONS request from curl you will get this response:
如果您尝试从curl发出OPTIONS请求,您将收到以下响应:
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Cache-Control, Pragma, Origin,
Authorization, Content-Type, X-Requested-With, authorization-token
Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS
Allow: GET,HEAD,POST
Content-Type: text/html; charset=utf-8
Content-Length: 13
ETag: W/"d-7cCV5tLYsy8ebraCH4f8nQ"
Date: Thu, 24 Mar 2016 19:56:49 GMT
Connection: keep-alive
So, my questions are:
所以,我的问题是:
1) Why OPTIONS request is not called if I remove custom HTTP header?
1)如果我删除自定义HTTP标头,为什么不调用OPTIONS请求?
2) What is missing in OPTIONS response, why it's aborted?
2)OPTIONS响应中缺少什么,为什么它被中止?
UPD:
Here are headers from original GET request. I can not see OPTIONS headers though.
这是来自原始GET请求的标题。我虽然看不到OPTIONS标题。
UPD2:
I was able to get this error message from Chrome dev tool for OPTIONS request:
我能够从Chrome开发工具中获取OPTIONS请求的此错误消息:
net::ERR_CONNECTION_REFUSED
1 个解决方案