由于 php 后端仅接受 'x-www-form-urlencoded',如何在 Angular 2 中发送正确格式的有效负载?

How to send right format of payload in Angular 2 since the php backend accept only 'x-www-form-urlencoded'?

首先我设置 headers:

this.headers.append("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

然后我用户 http.put 所以发送请求

isExistingEmail(email:string):void{

        this.http.post(
            GLOBAL_CONST.apiPath + "/user/user/api-check-user-email",
            {email:email},
            {headers:this.headers}
        )
        .map(res => res.json())
        .subscribe(
            (data) => {
                console.log(data);
            },
            (err) => {
                console.log(err);
            }
        );
    }

这是结果
这应该是

问题是,您试图发送 JSON 数据,而不是表单数据。

你应该用 "email=your@mail.com" 之类的东西替换 {email:email} - 它应该是一个字符串,幸运的是我们在 TS (ES6) 中有模板字符串,使用它们