我已经添加了授权密钥,如下所示
postrequest(callurl, input) {
const headers: any = new Headers;
headers.append('Content-type', 'application/json;charset=utf-8');
headers.append('Authorization', 'Bearer
'+localStorage.getItem("AuthTocken"));
return this._http.post(callurl, input, headers)
.pipe(
map((res: any) => {
return res;
}),
retry(2),
catchError(err => {
})
);
}
我没有计算任何错误,但在 Headers 中找不到 Authorisation
@ angular / common / http URL使用的角度6服务在邮递员中正常工作
我得到如下错误
http.service.ts:84后端返回代码0,正文为:[object ProgressEvent]正文为:{“headers”:{“normalizedNames”:{},“lazyUpdate”:null,“headers”:{}}, “status”:0,“statusText”:“Unknown Error”,“url”:null,“ok”:false,“name”:“HttpErrorResponse”,“message”:“(未知网址)的Http失败响应:0未知错误“,”错误“:{”isTrusted“:true}}(匿名)@ http.service.ts:84 push ../ node_modules / rxjs / _esm5 / internal / operators / catchError.js.CatchSubscriber.error @catchError的.js:34
Responce Headers enter image description here
2 回答
你必须使用
Bearer
而不是Token
Headers 对象是一个选项 . 你必须在下面的表格中传递 Headers 作为参数
this.http.post(url, data, { headers: headers })
它需要稍微不同的设置 .
编辑:为简洁起见
通过,我意识到你拼写授权错了 . 因此,它不会被认为是标准 Headers .