0

I am trying to use HTTPClient to upload a form to my backend server (Java/Springboot). When I try to add the authorization header, the network debug does not show the header added in my post request for upload.

Here is the code that I am using

import { HttpClient, HttpHeaders } from '@angular/common/http';

.....
....


let httpHeaders = new HttpHeaders();
httpHeaders = httpHeaders.set('Authorization', 'Bearer ' + AuthService.getToken());

this.http.post(serverURL, formData, {headers : httpHeaders}).subscribe(
  (res) => console.log('server response =' + JSON.stringify(res)),
  (err) => console.log('server err =' + JSON.stringify(err))
);

Here are the screenshots from the network debug

enter image description here

enter image description here

enter image description here

Can some one please suggest what could have caused this?

user1223879
  • 123
  • 3
  • 13
  • I could solve this issue by following https://stackoverflow.com/questions/45901160/angular-4-3-httpclient-doesnt-send-authorization-header?rq=1 and https://stackoverflow.com/questions/49471172/springboot-endpoint-403-options-when-doing-a-post-request – user1223879 Jan 02 '20 at 01:45

1 Answers1

0
let httpHeaders = new HttpHeaders()
.set('Authorization', 'Bearer ' + AuthService.getToken());

You can use like this

Praveen Patel
  • 349
  • 7
  • 24