【问题标题】:Content type 'text/plain;charset=UTF-8' not supported for post request in angular 4Angular 4 中的发布请求不支持内容类型“text/plain;charset=UTF-8”
【发布时间】:2018-01-11 07:58:30
【问题描述】:

我正在使用HttpClient 的发布请求,如下所示,

return this.httpclient.post<any>(url, body)
            .catch(this.handleError)

然后它给了我以下错误,

不支持内容类型“text/plain;charset=UTF-8”

然后我尝试添加如下标题,

const headers = new HttpHeaders({'Content-Type':'application/json; charset=utf-8'});


        return this.httpclient.post<any>(url, body, {headers: headers})
            .catch(this.handleError)

然后它给了我以下错误,

预检响应包含无效的 HTTP 状态代码 403

  • 这适用于 get 请求。

这是什么原因。希望您对此有所帮助

【问题讨论】:

  • 尝试用邮递员发出请求,然后看看哪些头参数起作用
  • 是的,它工作正常@AshrafulIslam

标签: angular post httpclient


【解决方案1】:

尝试这样的想法:

 let body = {dataToSend};
         this.httpClient.post(url, body)
        .subscribe(function(data) {
                console.log(data);
        });

对我有用

【讨论】:

    猜你喜欢
    • 2023-02-15
    • 2014-09-18
    • 2019-11-23
    • 2018-05-15
    • 2021-08-05
    • 2018-07-12
    • 2019-12-22
    • 2018-07-24
    • 2015-11-01
    相关资源
    最近更新 更多