Hello guys,
I am trying to load URL (which is SSRS Report) which is having authentication. Below is the code
let header = new Headers();
header.append(‘Access-Control-Allow-Origin’,‘http://localhost:8100’);
header.append(‘Access-Control-Allow-Credentials’, ‘true’);
header.append(“Access-Control-Allow-Headers”, “Content-Type, Authorization, Content-Length, X-Requested-With”);
header.append(“Access-Control-Allow-Methods”, “GET, POST, OPTIONS”);
header.append(‘Authorization’, 'Basic ’ + btoa(username:password));
let options = new RequestOptions({ headers: header});
this.http.get(url, options)
.map(res => res.text())
.subscribe(data => {
console.log("success: " + data);
this.myVal = data;
}, err => {
console.log("error: " + err);
this.myVal = err;
});
When i run it, receiving the following error
XMLHttpRequest cannot load https://xxx. Response for preflight has invalid HTTP status code 401.
When i checked in browser Developer tools, under Network tab i can see the below error.
I understand this error is due to the preflight request (sending authorization in header) but not sure how to resolve this error as there is nothing i can do much on server side. Coz, when i execute the same URL using Boomerang (an extension in chrome) it is getting the response.
Thank you