两者有什么区别
请求。ContentType = "application/json; "charset = utf - 8”;
and
webRequest。ContentType = "application/x-www-form-urlencoded";
两者有什么区别
请求。ContentType = "application/json; "charset = utf - 8”;
and
webRequest。ContentType = "application/x-www-form-urlencoded";
当前回答
webRequest。ContentType = "application/x-www-form-urlencoded";
Where does application/x-www-form-urlencoded's name come from? If you send HTTP GET request, you can use query parameters as follows: http://example.com/path/to/page?name=ferret&color=purple The content of the fields is encoded as a query string. The application/x-www-form- urlencoded's name come from the previous url query parameter but the query parameters is in where the body of request instead of url. The whole form data is sent as a long query string.The query string contains name- value pairs separated by & character e.g. field1=value1&field2=value2 It can be simple request called simple - don't trigger a preflight check Simple request must have some properties. You can look here for more info. One of them is that there are only three values allowed for Content-Type header for simple requests application/x-www-form-urlencoded multipart/form-data text/plain
3.对于大多数平坦的参数树,application/x-www-form-urlencoded是经过尝试和测试的。
请求。ContentType = "application/json; "charset = utf - 8”;
数据将是json格式。
axios和superagent是两个比较流行的npm HTTP库,默认情况下使用JSON主体。
{ “id”: 1、 “名称”:“Foo”, “价格”:123年, “标签”:[ “酒吧”, “唷” ), “股票”:{ “仓库”:300年, “零售”:20 } }
"application/json" Content-Type是预飞行请求之一。
现在,如果请求不是简单请求,浏览器会在发送原始请求之前通过OPTIONS方法自动发送一个HTTP请求,以检查发送原始请求是否安全。如果可以,就发送实际请求。你可以在这里找到更多信息。
Application /json是初学者友好的。URL编码的数组可能是一个噩梦!
其他回答
两者之间最大的区别之一是JSON编码post通常会保留发送的值的数据类型(只要它们是有效的JSON数据类型),而application/x-www-form-urlencoded通常会将所有属性转换为字符串。
例如,在json编码的帖子中:
{"Name": "John Smith", "Age": 23}
服务器很可能将Age属性解析为整数23。
而在
Name=John+Smith&Age=23
服务器很可能将Age解析为字符串“23”。
当然,如果您使用其他层来解析这些值并将它们转换为适当的类型,这可能不是问题。
webRequest。ContentType = "application/x-www-form-urlencoded";
Where does application/x-www-form-urlencoded's name come from? If you send HTTP GET request, you can use query parameters as follows: http://example.com/path/to/page?name=ferret&color=purple The content of the fields is encoded as a query string. The application/x-www-form- urlencoded's name come from the previous url query parameter but the query parameters is in where the body of request instead of url. The whole form data is sent as a long query string.The query string contains name- value pairs separated by & character e.g. field1=value1&field2=value2 It can be simple request called simple - don't trigger a preflight check Simple request must have some properties. You can look here for more info. One of them is that there are only three values allowed for Content-Type header for simple requests application/x-www-form-urlencoded multipart/form-data text/plain
3.对于大多数平坦的参数树,application/x-www-form-urlencoded是经过尝试和测试的。
请求。ContentType = "application/json; "charset = utf - 8”;
数据将是json格式。
axios和superagent是两个比较流行的npm HTTP库,默认情况下使用JSON主体。
{ “id”: 1、 “名称”:“Foo”, “价格”:123年, “标签”:[ “酒吧”, “唷” ), “股票”:{ “仓库”:300年, “零售”:20 } }
"application/json" Content-Type是预飞行请求之一。
现在,如果请求不是简单请求,浏览器会在发送原始请求之前通过OPTIONS方法自动发送一个HTTP请求,以检查发送原始请求是否安全。如果可以,就发送实际请求。你可以在这里找到更多信息。
Application /json是初学者友好的。URL编码的数组可能是一个噩梦!
第一种情况是告诉web服务器你正在发布JSON数据:
{"Name": "John Smith", "Age": 23}
第二种情况是告诉web服务器你将在URL中编码参数:
Name=John+Smith&Age=23