四种常见的 POST 提交数据方式:
1.application/x-www-form-urlencoded
2.multipart/form-data
3.application/json
4.text/xml
post请求需要在header中指定Content-Type
application/x-www-form-urlencoded和multipart/form-data的区别
当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…),然后把这个字串append到url后面,用?分割,加载这个新的url。
当action为post时候,浏览器把form数据封装到http body中,然后发送到server。
如果没有 type=file 的控件,用默认的 application/x-www-form-urlencoded 就可以了。
但是如果有 type=file 的话,就要用到 multipart/form-data 了。浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition(form-data或者file)、Content-Type(默认为text/plain)、name(控件name)等信息,并加上分割符(boundary)。