0
votes

angular http call:

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);
      });

  }

response

Not using code formating as it is eaiser to read without it.

ERROR HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:4200/", ok: false, …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}status: 200statusText: "OK"url: "http://localhost:4200/"ok: falsename: "HttpErrorResponse"message: "Http failure during parsing for http://localhost:4200/"error: {error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at XMLHtt…, text: "↵↵↵ ↵↵"}proto: HttpResponseBase

httpclient defaults to returning the json of the response, and that is something I am actively researching. But I am not sure how to fix this.

2

2 Answers

0
votes

You get 200 because you succeed to get to the server but you have issues with the payload. It seemed you need to send JSON and you sending something that started with < which isn't JSON. you can use this site to check if you send valid JSON: https://jsonformatter.curiousconcept.com/

I hope it was helpful.

0
votes

So pretty easy fix just had to change the response type to text.

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;