为HTTP创建头请求
问题描述:
我想创建一个HTTP头信息要求其应具有如下键和值为HTTP创建头请求
目前,我这样做是为了实现它:
let header= new Headers();
header.append('Authorization','Token '+this.auth.data.authtoken);
但它是401未经授权的回应。但在邮递员工作。
答
你可以像
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization': api_token);
let options = new RequestOptions({ headers: headers });
return this.http
.get(url, options);
+0
看看我的功能和回答部分的答案 –
答
添加页眉当设置Authorization头。它的标准是在认证令牌和前缀之间有一个空间 。
let header= new Headers(); header.append('Authorization','Token ' + ' '+ this.auth.data.authtoken);
此外,您还需要附加Content-type标头。
你可以设置选项吗?让options = new RequestOptions({headers:headers});然后通过这个作为发布请求的第三个选项 – LLai
看看我的获取文件功能,它的响应 –