0
votes

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.

1
do you get the authorization token in console? - Ammar Hussain
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). - R. Richards

1 Answers

1
votes

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