首页 > 解决方案 > angular ionic - jwt 令牌标头发布错误

问题描述

ionic v3中,我使用以下代码通过jwt插件与wordpress api用户进行通信

我使用波纹管代码进行令牌验证,但它不起作用,在其他情况下,当我在邮递员或在线请求工具中测试时,此标头验证有效,所以我认为它与服务器端无关:

validateAuthToken(token){
    return this.http.post(this.API_USER_VALID, {} , {headers: {'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Bearer ' + token}})
      .subscribe((validdata)=>{
        console.log(validdata);
      });
  }

错误错误图像

对于登录,我使用下面的代码,它工作正常(通过'Content-Type': 'application/json'标头不起作用,但使用'Content-Type': 'application/x-www-form-urlencoded' 工作):

doLogin(username,password){
    return this.http.post(this.API_LOGIN,"username=" + username +
      "&password=" + password,{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
      .subscribe((ddaa)=>{
        console.log(ddaa);
      });
  }

我卡住了:(,如果有向导请告诉我

标签: angularheaderionic3jwtwordpress-rest-api

解决方案


在后端设置 CORS 并指定标头


推荐阅读