【问题标题】:Angular failed post request with error 500Angular 发布请求失败,错误为 500
【发布时间】:2021-01-10 13:13:21
【问题描述】:

我正在开发一个离子应用程序,该应用程序对后端进行休息调用以发送电子邮件,当我进行休息通话时,我收到以下错误,可能是由于(邮递员中的休息通话有效,我使用 chrome禁用cors)

错误:

POST http://172.16.50.92/send 500 (Internal Server Error)

代码角度:

 const params = {
            'type': 'mail',
            'attributes[to_recipients]': mail,
            'attributes[body]': body,
            'attributes[subject]': subject,
            'attributes[attachments]': attachments
        };
         endpoint = url + '/send';
        
         var headers_object = new HttpHeaders();
         headers_object.append('contentType', 'application/json');
         headers_object.append('Authorization', `Basic ${window.btoa(username + ':' + password)}`);
         return this.http.post(endpoint, params, [headers_object]);

【问题讨论】:

  • 尝试Content-Type 而不是contentType。相关doc.
  • 我已经尝试过这个解决方案,但我有同样的错误

标签: json angular rest ionic-framework ionic4


【解决方案1】:

return this.http.post(endpoint, params, [headers_object]);

您将标题放入一个数组中。但是签名应该是

post(url: string, body: any, options: { headers: HttpHeaders })

适合您的用例。

请换到下面再试一次。

return this.http.post(endpoint, params, { headers: headers_object });

【讨论】:

    猜你喜欢
    • 2019-02-25
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 2015-07-11
    • 2020-05-29
    相关资源
    最近更新 更多