【问题标题】:Angular HttpClient POST sends Request Payload instead of Form DataAngular HttpClient POST 发送请求有效负载而不是表单数据
【发布时间】:2018-07-16 22:18:02
【问题描述】:

我正在尝试使用表单数据元素(这是 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};
        },
        () => {
        }
    );

示例帖子:

【问题讨论】:

    标签: angular http rxjs httpclient


    【解决方案1】:

    看来我要发送的正文必须被字符串化,所以我导入了qs 并做了qs.stringify({...}) 并且它起作用了。

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2013-06-29
      • 1970-01-01
      • 2012-07-11
      • 2019-12-19
      • 2019-11-14
      相关资源
      最近更新 更多