2

I get this error when receiving a response from the server even though I put responseType as 'text' in the header :

   HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "https://beta.rokhas.ma/karazortal/web.jsp", ok: false, …}
error
:
{error: SyntaxError: Unexpected token < in JSON at position 15 at JSON.parse (<anonymous>) at XMLHtt…, text: "↵↵ ↵ ↵ ↵↵ ↵   ↵↵<!doctype html>↵ ↵↵<html lang="fr">…ight:0;border:0"></iframe>↵</body> ↵    ↵</html>↵"}
headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message:"Http failure during parsing for https://beta.rokhas.ma/karazortal/web.jsp"
name: "HttpErrorResponse"
ok:false
status:200
statusText: "OK"
url : "https://beta.rokhas.ma/karazortal/web.jsp"
__proto__ : HttpResponseBase

I want to display this HTML body content in my app.

myservice.ts

logIn(user){
    let body = new URLSearchParams();
    body.set('j_username', user.email);
    body.set('j_password', user.password);
    let headers= new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'})
    headers.append('responseType', 'text');
    const httpOptions = {
      headers: headers  
    };   
    console.log(body.toString());  
    return this.http.post(this.API_URL+'karazortal/kas/signin',  
     body.toString(),  httpOptions)

  }
1

1 Answer 1

3

This is work for me. please check it out.

logIn(user) {
  let body = new URLSearchParams();
  body.set('j_username', user.email);
  body.set('j_password', user.password);
  let headers= new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'});
  const httpOptions = {
    headers: headers
  };
  console.log(body.toString());
  return this.http.post(this.API_URL+'karazortal/kas/signin', body.toString(),{responseType: 'text'},  httpOptions)
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.