加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

错误:422(不可处理的实体). Angular4

发布时间:2020-12-17 17:10:34 所属栏目:安全 来源:网络整理
导读:我试图将localhost:4200上的Angular4数据发布到localhost:8000上的API.我和Postman合作得很好,但是和Angular不一样.然后我得到: 无法加载资源:服务器响应状态为422(不可处理的实体) 这是发布到api的服务: @Injectable()export class ApiService { const
我试图将localhost:4200上的Angular4数据发布到localhost:8000上的API.我和Postman合作得很好,但是和Angular不一样.然后我得到:

无法加载资源:服务器响应状态为422(不可处理的实体)

这是发布到api的服务:

@Injectable()
export class ApiService {
    constructor(private http: Http) { }
    login(username: string,password: string): Observable<Response>{
        const url = 'http://localhost:8000/login';
        const json = JSON.stringify({username: username,password: password});
        const headers: Headers = new Headers();
        headers.append('Content-Type','application/json; charset=UTF-8');
        return this.http.post(url,json,headers )
            .map(res => res.json());
    }
}

这是运行该方法的代码

logIn(user: string,password: string){
      this.apiService.login(user,password).subscribe(
          data => console.log(data),error => console.log(error)
      );
    }

解决方法

The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate),and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained
instructions.

例如,如果XML请求主体包含格式正确(即语法正确)但语义错误的XML指令,则可能发生此错误情况.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读