角度4中的帖子请求不支持内容类型'text/plain; charset = UTF-8' [英] Content type 'text/plain;charset=UTF-8' not supported for post request in angular 4

查看:186
本文介绍了角度4中的帖子请求不支持内容类型'text/plain; charset = UTF-8'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将发帖请求与HttpClient一起使用,如下所示,

I'm using post request with HttpClient like below,

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

然后它给了我下面的错误,

then it gives me below error,

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

Content type 'text/plain;charset=UTF-8' not supported

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

Then I tried to add headers like below,

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


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

然后它给了我下面的错误,

then it gives me below error,

对预检的响应具有无效的HTTP状态代码403

  • 这对于get请求可以正常工作.
    • this works fine with get request.
    • 这是什么原因.希望您对此有帮助

      what is the reason for this. hope your help with this

      推荐答案

      尝试这样的想法:

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

      对我有用

      这篇关于角度4中的帖子请求不支持内容类型'text/plain; charset = UTF-8'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆