简体   繁体   English

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

[英]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: 我有一些要执行的请求,直到现在我都将Http.post与json一起使用,如下所示:

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. 正如我在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将表单数据添加为 JMETER 正文 - How to add form-data as JMETER body 是否可以在 POST 请求正文中发送 Json 数据和图像作为表单数据 - Is it possible to send Json Data in the POST request body and an image as form-data 使用主体表单数据的nativescript发布请求 - nativescript post request using body form-data Angular2 http.post 和未定义的 req.body - Angular2 http.post and undefined req.body 如何在没有 HTTP 的情况下从 Angular2 (TypeScript) 中的 json 获取数据? - How to fetch data from json in Angular2 (TypeScript) without HTTP? 如何使用 URLSession 将此 JSON 数据作为 HTTP 正文发布? - How to post this JSON data as HTTP body using URLSession? 如何将 Postman 正文中带有嵌套数组字段的原始 JSON 转换为表单数据? - How to convert raw JSON with nested array field in Postman body into form-data? 如何使用 OpenAPI 3 在 multipart/form-data 请求的请求正文中格式化 JSON 数组? - How to format a JSON array in the request body of a multipart/form-data request with OpenAPI 3? 如何使用凌空传递URL的正文标签的表单数据 - How to pass form-data of body tag of URL using volley 如何将json添加到java中的http帖子的主体 - How to add json to the body of an http post in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM