我发出一个POST请求,请求刚好位于待处理状态,直到最终失败。我监视了nginx日志和节点服务器日志,并且请求甚至没有注册。除另一个同事之外,这对其他任何人都有效。如果我使用边缘浏览器或其他计算机,它可以正常工作。仅适用于Chrome和Firefox的选项(失败)
我试图向其他(自定义)服务器发出POST请求,并且它也挂在选项上。我也使用jQuery发出了POST请求,并且它以相同的方式失败。
也许值得注意的是,我正在使用withCredentials标志。
页眉:
Provisional headers are shown
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:GET
Origin:http://localhost:8080
Referer:http://localhost:8080/<path>
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36
请求:
public login(user) {
const endpoint = `http://<url>`;
let headers = new Headers();
headers.append('Content-type', 'application/json');
return this.http
.post(endpoint, JSON.stringify(user), {
headers: headers,
});
}
我订阅我的组件调用:
this._accountService.login(this.user)
.subscribe(res => {
console.log("logged in!");
if (res.json().status === "success") {
window.location.href = `/home/${this.org}/${this.product}`;
}
else {
// What other options are there?
console.log("Do something else maybe?");
}
},
err => {
this.invalidLogin = true;
console.log("Ye shall not pass!");
});
成功的用户的头部
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:<url>
Origin:<url>
Referer:<url>
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.33 Safari/537.36
将Chrome://网内部/#事件
t=61869793 [st= 0] +REQUEST_ALIVE [dt=60162]
--> has_upload = false
--> is_pending = true
--> load_flags = 34624 (DO_NOT_SAVE_COOKIES | DO_NOT_SEND_AUTH_DATA | DO_NOT_SEND_COOKIES | MAYBE_USER_GESTURE | VERIFY_EV_CERT)
--> load_state = 14 (WAITING_FOR_RESPONSE)
--> method = "OPTIONS"
--> net_error = -1 (ERR_IO_PENDING)
--> status = "IO_PENDING"
--> url = "<url>"
t=61929955 [st=60162] -HTTP_STREAM_PARSER_READ_HEADERS
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] -HTTP_TRANSACTION_READ_HEADERS
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] -URL_REQUEST_START_JOB
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] URL_REQUEST_DELEGATE [dt=0]
t=61929955 [st=60162] -REQUEST_ALIVE
--> net_error = -324 (ERR_EMPTY_RESPONSE)
我真的猜这是关系到的东西,在我的浏览器(一个或多个),但我缓存真的找不到什么。我已经清除了所有可以存储的cookies和任何东西。我还可以在哪里检查以清除事情?这显然是我的电脑/浏览器(和另一个不幸的人)的本地东西。
http://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin –
这与Angular无关。您正在访问的服务器需要支持CORS请求。 'OPTIONS'是浏览器自主进行的预检请求。如果它没有返回预期的'Access-Control-Allow -...'标头,它甚至不会尝试发送实际的请求。 –
@GünterZöchbauer我启用了CORS。该请求适用于其他计算机和浏览器。 – Aarmora