0

I have http patch request with Bearer Token Authorization. But the Http Request get a Unauthorized error from the Server, when making the exact same Request(console.log(url + token) and then copy it from the console) in Postman, it works.

What could be the Problem ?

this.getToken().subscribe((data: FormData) => {
      const httpOptions = {
        headers: new HttpHeaders({
          'Authorization': ('Bearer ' + data['access_token'])
        })
      }
      console.log("URL with " + httpOptions.headers.get("Authorization"));
      this.http.patch("URL",httpOptions).subscribe((articledata: Article)=>
{
        console.log(articledata);
      })
    });

So this should work, since copying the output and using it in Postman works, but i get a 401 Unauthorized.

2
  • do you get the authorization token in console? Jul 19, 2019 at 12:48
  • You're using this.http.patch incorrectly. The second parameter should be the body of the request, not the http options (that is the 3rd parameter). Jul 19, 2019 at 12:55

1 Answer 1

1

For Anyone that needs it, i used http.patch wrong, the headers are the 3rd parameter after url and body.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.