“对https://xxxx.xxx/sub/spot/1的Http错误响应:401未经授权”,

时间:2019-09-04 15:12:32

标签: angular nativescript response http-status-code-401 http-error

我的代码有问题。

我有:

  • HTTP方法POST
  • 端点https://xxxx.xxx/sub/spot/ {spotNo}
  • 页眉
    内容类型:application / json和X-TOKEN:

  • 路由参数:spotNo

为此,我创建了这样的服务:

public Sub(spotNo: string): Observable<Subscription> {
    return this.httpclient.post(Api.getUrl(Api.URLS.spot + '/' + spotNo), {
        headers: new HttpHeaders({
            'X-TOKEN': 'eyJ0e',
            'Content-Type': 'application/json'
        }),
        observe: 'response'
    }).pipe(map((response: HttpResponse<any>) => {
        return new Subscription(response)
      }, error => {
        console.log('err', error)
    }));
}

在组件中,我订阅了此功能

subscribespot() {  
    this.subservice.Sub(this.spotsid).subscribe(
        result => {
            console.log('result', result)
        },
        error => {
            console.log('errorr', error)
        }
    );
}

在邮递员中,我得到了正确的答复。

在控制台中显示此错误:

JS: errorr {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null
JS:   },
JS:   "status": 401,
JS:   "statusText": "Unauthorized",
JS:   "url": "https://xxxx.xxx/sub/spot/1",
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure response for https://xxxx.xxx/sub/spot/1: 401 Unauthorized",
JS:   "error": {
JS:     "status": "failed",
JS:     "message": "Wrong number of segments"
JS:   }
JS: }

0 个答案:

没有答案