Multipart/form-data POST文件上传详解
理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表达提交的,代码如下: <form method="post" action="http://w.sohu.com"> <input type="text" name="txt1"> <input type="text" name="txt2"> </form> 提交时会向服务器段发出这样的数据(已经去除部分不相关的头信息),数据如下: POST / HTTP/1.1 Content-Type:application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: w.sohu.com Content-Length: 21 Connection: Keep-Alive Cache-Control: no-cache txt1=hello&txt2=world 对于普通的HTML Form POST请求,它会在头信息里使用Content-Length注明内容长度。头信息每行一条,空行之后便是Body,即"内容"(entity)。它的Content-Type是application/x-www-form-urlencoded,这意味着消息内容会经过URL编码,就像在GET请求时URL里的QueryString那样