Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 发送post请求时出现Http响应错误4_Angular_Http Error - Fatal编程技术网

Angular 发送post请求时出现Http响应错误4

Angular 发送post请求时出现Http响应错误4,angular,http-error,Angular,Http Error,当我从服务器接收响应时,即使我将responseType作为'text'放在标题中,也会出现此错误: HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "https://beta.rokhas.ma/karazortal/web.jsp", ok: false, …} error : {error: SyntaxError: Unexpected token < in JSON a

当我从服务器接收响应时,即使我将
responseType
作为
'text'
放在标题中,也会出现此错误:

   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

这是我的工作。请检查一下

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)
}
. 顺便说一句,即使您必须修改头来设置响应类型,您的代码也不会,因为HttpHeaders是不可变的。
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)
}