【问题标题】:auth0 authorization api call returns 200 status yet still getting error responseauth0 授权 api 调用返回 200 状态但仍然得到错误响应
【发布时间】:2020-05-05 13:32:35
【问题描述】:

角度 http 调用:

login(){
    const loginstring = 'https://<removed>.auth0.com/authorize?' +
      'response_type=token&' +
      'client_id=<removed>&' +
      'connection=null&' +
      'redirect_uri=<removed>';
    this.http.get(loginstring, {observe: 'response'}).subscribe(
      (req:any)=>{
        console.log('this is the http response');
        console.log(req);
      });

  }

回复

不使用代码格式化,因为没有它更容易阅读。

错误 HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:4200/", ok: false, ...}headers: HttpHeaders {normalizedNames: Map(0),lazyUpdate: null,lazyInit :ƒ}状态:200statusText:“OK”url:“http://localhost:4200/”ok:falsename:“HttpErrorResponse”消息:“解析http://localhost:4200/时Http失败”错误:{错误:SyntaxError:意外的令牌proto:HttpResponseBase

httpclient 默认返回响应的 json,这是我正在积极研究的。但我不确定如何解决这个问题。

【问题讨论】:

    标签: angular authentication error-handling auth0 angular-httpclient


    【解决方案1】:

    如此简单的修复只需将响应类型更改为文本。

    const loginstring = 'https://portaltech.auth0.com/authorize?' +
          'response_type=code&' +
          'client_id=MOqNyn7qyRhJdCOv5QHCUGkmjAv6Wied&' +
          'connection=null&' +
          'redirect_uri=http://localhost:4200/';
        this.http.get(loginstring, {responseType: 'text', observe:'response'}).subscribe(
          (req:any)=>{
            console.log('this is the http response');
            console.log(req.body);
            this.innerhtml = req.body;
    

    【讨论】:

      【解决方案2】:

      您会收到200,因为您成功访问了服务器,但有效负载存在问题。 看来您需要发送 JSON,而您发送的内容以 &lt; 开头,而不是 JSON。 您可以使用此站点检查您是否发送了有效的 JSON:https://jsonformatter.curiousconcept.com/

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-12
        • 1970-01-01
        • 1970-01-01
        • 2019-04-09
        • 2018-11-05
        • 2011-03-16
        • 2020-05-19
        • 2015-12-19
        相关资源
        最近更新 更多