我是 angular2 的新手。我的服务器(spring)在其响应标头中使用 set-cookie 值来响应身份验证。
如何将该 cookie 设置为下一次 API 调用的请求标头?
我搜索了很多,但找不到合适的解决方案。
作为http.get() or http.post() https://angular.io/docs/ts/latest/api/http/index/Http-class.html您可以指定的方法RequestOptionsArgs https://angular.io/docs/ts/latest/api/http/index/RequestOptionsArgs-interface.html
Use the Headers
in the RequestOptionsArgs
指定您需要的 auth 标头。
作为一个粗略的例子,请参见下面:
class PeopleComponent {
constructor(http: Http) {
let customHeaders: Headers = new Headers();
customHeaders.append('myHeaderName', 'myHeaderValue');
http.get('http://my.web/service', { headers: customHeaders })
.map(res => res.json())
.subscribe(people => this.people = people);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)