【发布时间】:2017-11-04 17:06:17
【问题描述】:
根据文档:https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS),对于简单请求不应进行预检。
如果我不在请求中添加额外的“授权”标头,情况确实如此:
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic _base64_string_"
没有“授权”标头:
:authority:www.target.com
:method:POST //<----------------This is correct
:path:/oauth2/access_token?client_id=xxx-xxx
:scheme:https
accept:application/json, text/plain, */*
accept-encoding:gzip, deflate, br
accept-language:en-US,en;q=0.8,fr;q=0.6
content-length:79
content-type:application/x-www-form-urlencoded//<----------------This is correct
origin:http://source.com:4200
referer:http://source.com:4200/
带有“Authorization”标头,自动设置OPTIONS方法:
:authority:www.target.com
:method:OPTIONS //<----------------This is NOT correct, caused by Authorization header
:path:/oauth2/access_token?client_id=xxx-xxx
:scheme:https
accept:*/*
accept-encoding:gzip, deflate, sdch, br
accept-language:en-US,en;q=0.8,fr;q=0.6
access-control-request-headers:authorization
access-control-request-method:POST
origin:http://source.com:4200
referer:http://source.com:4200/
由于这个问题,我无法授权我的应用,服务器响应是:
HTTP method 'OPTIONS' is not allowed. Expected 'POST'
因此,“授权”标头似乎触发了 CORS 中的预检。 任何人都可以对此有所了解吗?
【问题讨论】:
标签: angular cors authorization preflight