
[英]What is the correct way to set httpheaders to httprequest in angular4
[英]Angular4 HttpHeaders set incorrectly
我试图在不使用Angular(4.4.6) HttpClient的情况下设置POST请求。 但是,更改请求的标头的行为不正确。
这是代码:
const url = "http://...";
const body = { ... };
this.http.post(url, JSON.stringify(body), {
params: new HttpParams().set("Content-Type", "application/json; charset=utf-8"),
headers: new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8') <--
}).subscribe(res => console.log(res))
结果看起来像这样:
如您所见,未设置“ Content-Type”属性,尽管密钥存储在Access-Control-Request-Headers中 。
预期的行为类似于HttpParams(如您所见,设置正确)
有任何想法我在做什么错吗? 提前致谢!
尝试下面
let headers = new HttpHeaders().set('Content-Type', 'application/json');
this.httpClient.post(
`url`, data, { headers: headers}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.