本文介绍了角度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,
然后我尝试添加以下标题,
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,
- 这对于
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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!