I have to make calls with this format
https://username:[email protected]/api
in ajax I did something like this
$.ajax({
url: endPoint,
type: 'POST',
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
username: myUsername,
password: myPassword,
beforeSend: function (xhr) {
xhr.withCredentials = true;
xhr.setRequestHeader("Accept", "application/json; odata=verbose");
}
});
how can I do the same thing with the new Angular's HttpClient without doing something like this?
let url = baseProtocol + username + ":" + password + "@" + baseUrl
this.http.post(url,{
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
}
}).subscribe( res => {
//do stuff
}, err => {
//do other bad related stuff
}
it works but this string concatenation is ugly. I'm not a specialist of this kind of technology, I would appreciate some help