最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to send a list of files and data in a single HTTP multipart request? - Stack Overflow

programmeradmin2浏览0评论

I would like to send a HTTP POST request with multipart data to the server. I have both JSON and a file which I want to send in a single request. I know how to do it for a single file and a single JSON. Now, I have a list of JSONs with each JSON having its own file which I want to send in a single request as a multipart list. How can I do that?

This question is a pure HTTP question. I see similar questions here, but all which I looked into use some kind of a library. I want pure HTTP answer.

This is an example of a multipart request accepting single file and a single JSON:

POST https://server:23854/request HTTP/1.1

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary
----WebKitFormBoundary
Content-Disposition: form-data; name="graphicFile"; filename="file.name"
Content-Type: image/vnd.dwg
1
----WebKitFormBoundary
Content-Disposition: form-data; name="javaScriptObjectNotationData"
Content-Type: application/json
{
    "isThisJSON": true
}

Now, how can I send 2 files and 2 JSONs without using different part names and while maintaining order, so that first file corresponds to the first JSON, and second file to the second JSON?

So, on server, I want to read graphicFile part and javaScriptObjectNotationData part as two lists where item 1 in graphicFile part should correspond to item 1 in javaScriptObjectNotationData part. How should pure HTTP request look like which would achieve this?

发布评论

评论列表(0)

  1. 暂无评论