鍍金池/ 問(wèn)答/HTML5  HTML/ 怎么讓angular httpclient.post請(qǐng)求的body參數(shù)為鍵值對(duì)的

怎么讓angular httpclient.post請(qǐng)求的body參數(shù)為鍵值對(duì)的形式?

使用post請(qǐng)求時(shí),傳入的body參數(shù)是一個(gè)對(duì)象,得到的結(jié)果是這樣:
圖片描述
我希望他是這樣:
圖片描述
httpService中的代碼:

 private headers = new HttpHeaders({
     "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
  });
login() {
    let bo = {
      a: "參數(shù)1",
      b: "參數(shù)2"
    };
    this.http
      .request(
        new HttpRequest("POST", "api/search/suggest/multimatch", bo, {
          headers: this.headers
        })
      )
      .subscribe(re => {
        console.log(re);
      });
   }

求哪位大佬指點(diǎn)指點(diǎn)。。

回答
編輯回答
喜歡你

主要是因?yàn)榍昂蠖薱ontent-type設(shè)置不一致引起的;
在第三個(gè)參數(shù)中設(shè)置
headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'})
可以解決此問(wèn)題

2017年5月26日 00:01
編輯回答
陌如玉

使用$.param(data)為body.

this.http.post("api/search/suggest/multimatch", $.param(data), {
        params:  params,
        headers: this.headers
      })
      .subscribe(re => {
        console.log(re);
      });
 http://blog.csdn.net/maoguiyou/article/details/51891499
2017年10月25日 17:03
編輯回答
誮惜顏

請(qǐng)問(wèn)下,解決了嗎?我目前也是。post后php拿不到參數(shù)

2018年4月28日 18:19