简体   繁体   中英

How to use http 'POST' with form-data body instead of json body? (Angular2/Typescript)

I have some request I want to perform, and until now I used the http.post with json's like this:

this.http.post("https://somepath.com/users/login", JSON.stringify({"email": "someone@gmail.com","password":"123","user_token":"sss"}), RequestOptionsArgs);

but this won't work since this request to this website needs to be form-data body...how can I take this same call and change it to be form-data?

thanks!

As i can see in Angular 2 tests you should use FormData object. ie:

let body = new FormData();
body.append('email', 'someone@gmail.com');
body.append('password', '123');
this.http.post("https://somepath.com/users/login", body);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM