I'm trying to get string response from my back application. i searched for this issue and almost in all the solutions they add { responseType: "text"} or {responseType: 'text' as 'json'} to get string, i added it but i can't arrive, here my angular code:
msg:any;
func(){
this.bookService.getRessource(url,{ responseType: "text"})
.subscribe(data => {
console.log(data)
this.msg=data;
}, err => {
console.log(err)
})
}
This is my service, i have to add jwt to header:
getRessource(url,res){
let headers=new HttpHeaders({'Authorization':'Bearer '+this.authService.jwt});
return this.http.get(url,{headers:headers});
}
The funtion add a book to user's favorite list, it works and add it to database but the weird thing is the error message is shown in the console and i can find the string that i would like to get in that error. But i can't comprehend how the function works and then the error message is shown!!
This is the error message i receive:
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:8080/user/addBookToUser?username=admin&id=9", ok: false, …}
{responseType: 'text'}would be added as an option tothis.http.get()alongsideheaders. You aren't specifying{responseType: 'text'}in the actual HttpClient call currently.