我想通過使用Angular 2的http請求發送憑據,但Angular 2 Http get請求不會發送憑證。 我在做什麼錯?如何發送數據(Angular 2)?
$httpProvider.defaults.withCredentials = true;
所以您的應用程序的配置將是這個樣子:
var creds = "username=" + this.username + "&password=" + this.password;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
http.get('http://localhost:3000', {
headers: headers,
credentials: creds
})
.map(res => res.json())
.subscribe(
data => this.data(data),
err => this.error(err),
() => console.log('Done')
'RequestOptionsArgs'沒有憑據屬性:https://開頭的角.io/docs/ts/latest/api/http/RequestOptionsArgs-interface.html,它是一個'Header':https://angular.io/docs/ts/latest/api/http/Headers-class.html,你可以根據此規範設置標題:https://fetch.spec.whatwg.org/#headers-cl屁股,該憑據屬性設置了不同的東西,我相信你正在尋找'Authorization' Header來代替。 – Langley