我有CORS一個錯誤:CORS「否」Access-Control-Allow-Origin'標題出現在請求的資源上。「
「的XMLHttpRequest不能加載http://graphql-swapi.parseapp.com/響應預檢請求未通過訪問控制檢查:否‘訪問控制允許來源’標題存在於所請求的資源。原因'http://localhost:3000'因此不允許訪問。響應具有HTTP狀態碼405。「
當我調用服務方法時出錯。
代碼段:
let headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Methods', 'POST');
headers.append('Access-Control-Allow-Headers', 'Content-Type');
//console.log(headers);
return this._http.post(apiUrl, { query: query, vars: '{}' }, { headers: headers })
.map(res => res.json().data.planets);
當我關閉瀏覽器CORS,我得到:
的XMLHttpRequest無法加載XXX。預檢的響應具有無效的HTTP狀態碼405錯誤。
查詢和代碼肯定是正確的。
[「No'Access-Control-Allow-Origin'標頭存在於請求的資源中」](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-頭部是在請求的資源) – georgeawg