首页 > 解决方案 > Ionic 3/Angular 4/5 http 帖子 - 未找到

问题描述

在邮递员中,我有:

POST:    https://myapp.herokuapp.com/login
BODY:     {"email": "myemail@gmail.com", "password": "123456"}

它有效。

在提供者中,我有:

public login(credentials): Observable<any> {
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      })};

    return this.http.post(API_URL + '/login', {params: {email: credentials.email, password: credentials.password}}, httpOptions);
  }

我得到Not Found错误。在 Network 选项卡的控制台中,请求方法是 OPTIONS。怎么了?

编辑:我收到以下错误:

在此处输入图像描述

标签: angularpostionic-frameworkhttpclient

解决方案


尝试不使用params

public login(credentials): Observable<any> {
    const httpOptions = {
        headers: new HttpHeaders({
            'Content-Type':  'application/json'
        })
    };

    return this.http.post(API_URL + '/login', {email: credentials.email, password: credentials.password}, httpOptions);
}

如果这不起作用,那么这可能是由于CORS请求而发生的,这就是所谓的Preflighted requestOPTIONS当您调用CORS请求以了解实际允许的方法时,浏览器总是将请求发送到服务器。

看更多:


推荐阅读