Angular 6 SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse

Viewed 1430

I know this question has been already asked but I couldn't find any suitable solution.

I'm trying to make a post request. The API needs a x-www-form-urlencoded body format so I ended up doing like so:

login(account: LogAccount): Observable<any> {
 const body = new HttpParams()
  .set('username', account.username)
  .set('password', account.password);

  const headers = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });
  return this.http.post(`${environment.api.apiUrl}/loginservice`, body.toString(),
{ headers });

}

Which leads to :

enter image description here

Everything works fine using Postman. What am I missing here? Thanks

0 Answers
Related