我發出一個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