0

It may be REST or SOAP .... why should we use XML or JSON for request body for a web service why dont we use simple string like parameter=value&also=another in request body ( MIME TYPE: x-www-form-urlencoded )?

Actually it works on normal html form submission with php method ( MIME TYPE: x-www-form-urlencoded ) and it is default...

Doesnt it work on Web Services like REST ? If it works... on what reason XML or JSON is used instead? If reason regarding SOAP is that it uses HTTP+XML based protocol... lets skip it and consider only REST ......

4

1 回答 1

2

根据HTTP 规范,只要您提供适当的Content-type标头,您就可以在 HTTP 响应中发送您喜欢的任何内容类型。

JSON 和 XML 相对于普通查询字符串的主要好处是它们支持层次结构和复杂的数据结构,例如:

{"cars":[{"manufacturer":"Ford"}, {"manufacturer":"GM"}]}

或者

<cars>
   <car>
       <manufacturer>Ford</manufacturer>
   </car>
   <car>
       <manufacturer>GM</manufacturer>
   </car>
</cars>

这些类型的结构通常对 web 服务非常有用,并且不能用普通的查询字符串来实现。

于 2013-09-02T20:43:06.143 回答