Forum Discussion

Za_Dolber's avatar
Za_Dolber
New Contributor
8 years ago
Solved

How i can set header header in multipart/form-data POST request?

When i sent POST request with file and header "Content-Type: multipart/form-data" , and  via curl:

 

curl -i -X POST -H "Content-Type: multipart/form-data" -F "file=@/home/Za_Dolber/abon19.txt" http://somehost.somedomain:9876/service/add?ids=1

 

i see something like this in Wireshark:

 

POST /service/add?ids=1 HTTP/1.1
Host: somehost.somedomain:9876
User-Agent: curl/7.47.0
Accept: */*
Content-Length: 200
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------c47979a9d477ee1d

HTTP/1.1 100 Continue

--------------------------c47979a9d477ee1d
Content-Disposition: form-data; name="file"; filename="abon19.txt"
Content-Type: text/plain

1234567890

--------------------------c47979a9d477ee1d--
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 2

ok

 

But when i send same request via SoapUI:

 

 

POST /service/add?ids=1 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_0_1598092424.1491306778334"
MIME-Version: 1.0
Content-Length: 269
Host: somehost.somedomain:9876
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_0_1598092424.1491306778334
Content-Type: text/plain; charset=UTF-8; name=abon18.txt
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="abon18.txt"; filename="abon18.txt"

1234567890

------=_Part_0_1598092424.1491306778334--
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Content-Length: 47

Bad Request you must specify file with abonents

 

 

If i try set whole header field in "Headers" i get that header only in first part of request, like this:

 

 

POST /service/add?ids=1 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_1_662240902.1491314924683"
MIME-Version: 1.0
Content-Disposition: name="file"; filename="abon18.txt" 
Content-Length: 267
Host: somehost.somedomain:9876
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_1_662240902.1491314924683
Content-Type: text/plain; charset=UTF-8; name=abon18.txt
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="abon18.txt"; filename="abon18.txt"

79067212518

------=_Part_1_662240902.1491314924683--
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Content-Length: 47

Bad Request you must specify file with abonents

 

How can i change value of "name" field in Content-Disposition header?