表单json HTTP POST的内容类型? [英] Form content type for a json HTTP POST?
问题描述
只想澄清表单内容类型:
Just wanted a clarification of the form content types:
-
application / x-www- form-urlencoded
:这是你可以发送用url编码的params的地方。
application/x-www-form-urlencoded
: This is where you can send params encoded with the url.
multipart / form -data
:??
我需要在帖子中发送一个JSON(所以它会有类型: text / x-json
,我想)。
所以问题是, multipart / form-data
适用于此目的/是 application / x-www-form-urlencoded
更好?
I need to send a JSON in the post (so it would have the type: text/x-json
, I guess).
So the question is, is multipart/form-data
suitable for this purpose / is application/x-www-form-urlencoded
better?
此外,是否可以发送一些在url中编码的params,以及json中的一些数据?
Also, would it be possible to send some params encoded in the url, and some data in the json?
推荐答案
看起来人们回答了你问题的第一部分(使用application / json)。
It looks like people answered the first part of your question (use application/json).
对于第二部分:在HTTP POST请求中发送查询参数是完全合法的。
For the second part: It is perfectly legal to send query parameters in a HTTP POST Request.
示例:
POST /members?id=1234 HTTP/1.1
Host: www.example.com
Content-Type: application/json
{"email":"user@example.com"}
查询参数常用在POST请求中引用现有资源。上面的示例将更新ID为1234的现有成员的电子邮件地址。
Query parameters are commonly used in a POST request to refer to an existing resource. The above example would update the email address of an existing member with the id of 1234.
这篇关于表单json HTTP POST的内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!