2017-06-23 168 views
0

我想创建一个HTTP头信息要求其应具有如下键和值为HTTP创建头请求

enter image description here

目前,我这样做是为了实现它:

let header= new Headers(); 
header.append('Authorization','Token '+this.auth.data.authtoken); 

但它是401未经授权的回应。但在邮递员工作。

+0

你可以设置选项吗?让options = new RequestOptions({headers:headers});然后通过这个作为发布请求的第三个选项 – LLai

+0

看看我的获取文件功能,它的响应 –

回答

2

你可以像

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

看看我的功能和回答部分的答案 –

0

添加页眉当设置Authorization头。它的标准是在认证令牌和前缀之间有一个空间 。

let header= new Headers(); header.append('Authorization','Token ' + ' '+ this.auth.data.authtoken); 

此外,您还需要附加Content-type标头。