如何使用带有表单数据主体而不是 json 主体的 http 'POST'?(Angular2/Typescript)

Joe*_*Joe 3 json http typescript angular

我有一些想要执行的请求,到目前为止,我使用带有 json 的 http.post ,如下所示:

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

但这是行不通的,因为对该网站的请求需要是表单数据主体...我如何才能接受相同的调用并将其更改为表单数据?

谢谢!

Rem*_*Rem 5

正如我在Angular 2 测试中看到的,您应该使用 FormData 对象。IE:

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