• Post Reply Bookmark Topic Watch Topic
  • New Topic

sending an http request with a multipart/form-data

 
roy carmelo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make an http request to an with a multipart/form-data payload and this is what my payload looks like:

------WebKitFormBoundary
Content-Disposition: form-data; name="data"
Content-Type: application/vnd.ms-excel

EmployeeEmail,ManagerEmail,Admin
inviteThis@email.com,managers@email.com,false
------WebKitFormBoundary
Content-Disposition: form-data; name="requestJobDescription"
Content-Type: application/json

{
"type": "update",
"credentials": {
"partnerUserID": "somePartnerUserId",
"partnerUserSecret": "partner123user456secret789"
},
"inputSettings": {
"type": "employees",
"policyID":"some123policy456ID",
"fileType": "csv"
}
}

------WebKitFormBoundary--

I have tested the same exact payload to call directly call the API using postman and I get the ok status. However when I used this code:



Im not getting the ok status, instead Im getting an ERROR IN MULTIPART INITIALIZATION status.

Has anybody tried sending this kind of http request? Any idea how to get this working properly?

Thanks
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

roy carmelo wrote:Has anybody tried sending this kind of http request? Any idea how to get this working properly?

Try a 3rd party library like Apache HttpClient. That one makes it really easy. Here's an example: https://hc.apache.org/httpcomponents-client-ga/httpmime/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java
 
roy carmelo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sorry for the late reply. I was able so solve this using this example http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!