模拟多文件上传问题

我要模拟一个多文件提交

<form enctype="multipart/form-data" action="http://192.168.29.65/UploadFile" method=post>
    load multi files :<br>
    <input name="userfile" type="file"><br>
    <input name="userfile" type="file"><br>
    <input name="userfile" type="file"><br>
    <input name="userfile" type="file"><br>
    text field :<input type="text" name="text" value="text"><br>
    <input type="submit" value="提交"><input type=reset>
</form>

后端以一个userfile的文件数组接受

我怎么使用HttpClient的HttpPost来模拟文件数组上传。我单个文件会,但是想上面一样使用一个name的文件数组就不知道怎么写

阅读 2.2k
2 个回答
  1. RFC2388 - Returning Values from Forms: multipart/form-data

  2. Stackoverflow - what-does-enctype-multipart-form-data-mean

请求报文(来自Stackoverflow的回答):

POST / HTTP/1.1
[[ Less interesting headers ... ]]
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
Content-Length: 834

-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text1"

text default
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text2"

aωb
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file3"; filename="binary"
Content-Type: application/octet-stream

aωb
-----------------------------735323031399963166993862150--

把name改成userfile[]

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题