I want to read an e-mail address as a string from my backend using Spring MVC. However, when I try to read it using Angular's HttpClient
, I get the following error:
SyntaxError: Unexpected token b in JSON at position 0 at JSON.parse
This is a screenshot of the error displayed within the console:
This is the code I'm using in Angular to read the response:
public findEmail(username: string): Observable<string> {
let params = new HttpParams();
params = params.append('username', username);
return this.httpClient.get<string>(this.baseUrl + '/findEmail', {params});
}
And this is the code of the Spring controller that provides the response:
@GetMapping(value = "/findEmail", params = { "username" })
public String findEmail(@RequestParam String username) {
return utilisateursService.findEmail(username);
}