On Mon, Feb 26, 2018 at 5:27 PM, Arya F <[email protected]> wrote: > I made a post about this on Stackoverflow and never received an answer. > Here is the link to the post > https://stackoverflow.com/questions/48994951/apache-httpclient-include-boundary-in-multipart-form-data > > Here is what I am stuck on > > I have the following POST request which is supposed to upload a file. But I > can not figure out how to include the boundary in the request for the > "Content-Type" header. > > > HttpPost request = new HttpPost(url); > request.setConfig(config); > > StringEntity params = new StringEntity(""); > > HttpEntity entity = MultipartEntityBuilder.create() > .addBinaryBody("blob", file, > ContentType.create("application/octet-stream"), "filename").build(); > > request.addHeader("Host", "upload.twitter.com"); > request.addHeader("Connection", "keep-alive"); > request.addHeader("User-Agent", userAgent); > request.addHeader("Content-Type", ????????); > request.addHeader("Accept", "*/*"); > request.addHeader("Accept-Encoding", "gzip, deflate, br"); > request.addHeader("Accept-Language", "en-US,en;q=0.9"); > request.addHeader("Cookie", cookies); > > request.setEntity(entity); > response = httpClient.execute(request);
Arya, I am not sure why you are adding all the request headers manually. Things like the Content-Type should be handled from the entity automatically for you. A simple example code is available on the site at https://hc.apache.org/httpcomponents-client-ga/httpmime/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java Bindul > > int responseCode = response.getStatusLine().getStatusCode(); > > System.out.println("upload response code: " + responseCode); > > > > any idea how this is done? --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
