Search code examples
angularputpayloaddataform

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


First I set up my headers:

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

then I user http.put so send the request

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);
            }
        );
    }

This is the result
enter image description here and this is like it shoud be enter image description here


Solution

  • The problem is, that you trying to send JSON data, instead of Form data.

    You should replace {email:email} with something like "[email protected]" - it should be a string, fortunately we have template strings in TS (ES6), use them