Angular &引用;的Http失败响应https://xxxx.xxx/sub/spot/1: 401未经授权;,

Angular &引用;的Http失败响应https://xxxx.xxx/sub/spot/1: 401未经授权;,,angular,nativescript,response,http-status-code-401,http-error,Angular,Nativescript,Response,Http Status Code 401,Http Error,我的代码有问题 我有: HTTP方法POST 端点{spotNo} 标题 内容类型:application/json和X-TOKEN: 路线参数:spotNo 为此,我创建了如下服务: public Sub(spotNo: string): Observable<Subscription> { return this.httpclient.post(Api.getUrl(Api.URLS.spot + '/' + spotNo), { headers: n

我的代码有问题

我有:

  • HTTP方法POST
  • 端点{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)
    }));
}
在《邮递员》中,我得到了正确的回答

在控制台中显示此错误:

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: }

看起来使用的JWT令牌有问题。你确定你在这两种情况下使用的是正确的吗?是的,我确定,令牌是正确的。请分享一个游乐场示例,在那里可以复制该问题。
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: }