Below is my HTTP post request to get the auth token, the headers are not getting set, in chrome I don't see the headers under request headers.
What I also observed is, if I add only the content-type header I can see the header and body being sent in the request, if I add authorization header then no header or body being sent in the request and I see Response to preflight has invalid HTTP status code 401. error on console.
I also tried enabling "CORS" still the same issue.
have tried all the commented options.
let headers = new HttpHeaders({ 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'authorization': 'Basic ' + btoa("infoarchive.custom:mysecret") });
//headers = headers.append("content-type","application/x-www-form-urlencoded");
//headers = headers.append("authorization","Basic " + btoa("infoarchive.custom:mysecret"));
//headers = headers.set("Access-Control-Expose-Headers", "Authorization")
//headers = headers.set(Content-Type', 'application/x-www-form-urlencoded')
//headers = headers.set('Authorization', 'Basic aW5mb2FyY2hpdmUuY3VzdG9tOm15c2VjcmV0');
console.log(headers)
const body = JSON.stringify({
client_id: 'infoarchive.custom',
username: userName,
password: password,
grant_type: 'password',
scope: 'search'
});
return this.http.post('http://localhost:8080/oauth/token', body, { headers: headers })
.map(
(response: Response) => {
const data = response.json();
console.log("data:" + data)
// this.saveJwt(data.json().id_token);
}
)
.catch(
(error: Response) => {
console.log(error.status)
return Observable.throw('Something went wrong');
}
);
headers.append
instead ofheaders.set
– Commercial SuicidelazyUpdate
property in HttpHeaders, and not in the main list? – Guy Park