Angular HttpClient POST发送请求有效载荷而不是表单数据

时间:2018-07-16 22:18:03

标签: angular http rxjs httpclient

我正在尝试使用表单数据元素(API所支持的内容)发表文章,但是当使用.post时,它将发送请求有效载荷。

如果我将标头设置为"Content-Type": "application/x-www-form-urlencoded",则它将整个json作为键发送,并带有空白值 我在这里做什么错了?

this.http.post("/auth", {
    uaUserName: this.loginForm.controls.uaUserName.value,
    uaPassword: this.loginForm.controls.uaPassword.value
})
    .subscribe((data: Profile) => {
            this.profileProvider.profile = {...data};
        },
        () => {
        }
    );

示例帖子:

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

似乎我要发送的正文必须进行字符串化处理,因此我导入了qs并执行了qs.stringify({...})之后就可以了。