• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sending an http request with a multipart/form-data

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic