我正在使用Ionic 2(2.0.0-beta.10)的項目。我嘗試將請求傳遞給授權令牌。但是頭沒有被髮送。我試圖傳遞的其他標題也沒有被髮送。Ionic 2/Angular 2/CORS:HTTP頭沒有被請求發送
let url = 'http://www.example.com/savedata';
let data = JSON.stringify({ email: '[email protected]', password: '123456' });
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer ' + "tokenContent");
let options = new RequestOptions({ headers: headers });
this.http.post(url, data, options).map(res => res.json()).subscribe(data => {
console.log("it worked");
}, error => {
console.log("Oooops!");
});
我的REST API接收到這個請求,有以下標題:
Host: www.example.com
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://evil.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36
Access-Control-Request-Headers: authorization, content-type
Accept: */*
Referer: http://localhost:8100/?restart=794567
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
的數據(體)進來正確的,只是標題問題,我解決不了。 任何幫助將不勝感激。
你可以嘗試傳遞這樣的'this.http.post(url,data,{headers:headers})這樣的頭文件....' – AngJobs
我試圖做到這一點,但是我在REST API中收到的頭文件發送請求如下:主機\t \t www.example.com連接 \t保活\t 的Content-Length \t \t 45原產 \t \t http://evil.com/ 用戶代理\t的Mozilla/5.0( Windows NT 6.1; WOW64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/51.0.2704.106 Safari/537.36 \t Content-Type \t text/plain \t Accept \t */* \t Referer \t http:// localhost:8100 /?重啓= 794567 \t 接受編碼gzip的\t,縮小\t 接受語言\t EN-US,EN; Q = 0.8 – GwenTiana
正常,檢查這個答案http://stackoverflow.com/questions/38301878/ionic-2-angular -2-http-headers-are-not-being-along-with-the-request – AngJobs