所以我是新来的有角度的人,我正在尝试发出发布请求,但事实是,我需要将content-type设置为application / json,一旦发送所有变量,我的请求就会停止工作在url上它可以工作,但是我想在主体上发送pw,为此,我需要设置content-type。简而言之,如果我这样做,它将起作用:
let resp: any;
var req = {
pw: this.pw
};
this.httpClient.post(this.baseUrl + 'login?login=' + this.log + '&key=' + this.key + '&pw=' + this.pw,req)
但是如果我这样做,将无法正常工作(也需要对API进行更改)
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json; charset=utf-8'
})
};
let resp: any;
var req = {
pw: this.pw
};
this.httpClient.post(this.baseUrl + 'login?login=' + this.log + '&key=' + this.key,req, httpOptions)
谢谢你们。
虽然提供http.post()的标头,但您必须将其提供为键值为headers
的键值对。
const headers = new HttpHeaders({'Content-Type':'application/json; charset=utf-8'});
在您的发帖方式中,
this.httpClient.post(this.baseUrl + 'login?login=' + this.log + '&key=' + this.key,req, {headers: headers })
虽然提供http.post()的标头,但您必须将其提供为键值为headers
的键值对。