当我添加 Authorization
header 时,AngularJS 将我的 POST
请求转换为 OPTIONS
:
$http({
url: ApiEndpoint + 'logout',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': UserService.getApiKey()
}
})
我正在开发一个带有 Ionic 的混合移动应用程序,我在浏览器中对其进行了测试,因为它是一个 CORS 请求。
我已经看到了this问题。建议的解决方法是更改我所做的 Content-Type
,并且它在没有 Authorization
的情况下工作。使用 Authorization
header ,请求再次更改为 OPTIONS 方法。
您能否提出客户端解决方案,因为无法控制服务器 API。
谢谢。
最佳答案
作为Developer备注,CORS 请求将被预检,除非它是 simple request .
关于javascript - CORS,防止带有授权 header 的请求预检,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39066786/