我直接在Azure基础架构上托管Azure功能。在本地开发Web前端并在其他域上部署它时,我面临一个奇怪的问题,即Angular在POST请求之前发送OPTIONS请求。
为了解决这个问题,我确实为所有位置启用了CORS(“*”)。不过,我认为首先是OPTIONS请求。关于如何禁用它的任何指针?
以下是导致问题的Angular代码:
var headers = new Headers({
"Content-Type": "application/json",
"Accept": "application/json"
});
headers.delete('Cache-Control');
headers.delete('Pragma');
headers.delete('If-Modified-Since');
headers.delete('X-Content-Type-Options');
headers.append('Cache-Control', 'no-cache');
headers.append('Pragma', 'no-cache');
headers.append('If-Modified-Since', '0');
headers.append('X-Content-Type-Options', 'nosniff');
return this.http.post(
this.postUrl,
('{"email": "' + email + '", "password": "' + encryptedPassword + '"}'),
{
headers: headers
}
).map(res => res.json());