0

I have huge json data to upload on server, but when I upload using HttpPost getting SocketTimeout Exception, while I changed timeout to 25000 and more.

Does anyone has solution for it?

Does MultiPartEntity will help me in this case ?

If yes then how to send json data on server using MultiPartEntity?

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69

1 Answers1

0

Yes MultiPartEntry from Apache MIME can help you in this case. It is sometimes used for uploading images with some contextual data in multiple parts. For sending Json you can do something like this

You will have to use MultipartEntityBuilder to create MultipartEntity object.

//use builder as MultipartEntity is deprecated
MultipartEntityBuilder builder = MultipartEntityBuilder.create();        
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

String yourJsonString = yourJSONObject.toString();

builder.addPart("key_to_yourJsonString", yourJsonString ); //set your Json String
HttpEntity entity = builder.build();        //create entity
httppost.setEntity(entity);               
response = httpClient.execute(httppost);

you would require httpclient.jar, httpcore.jar, httpmime.jar, httpclient.jar, commons-codec.jar and commons-logging.jar to be in classpath.

Refer the below links for more info on this. bethecoder MultipartEntityDeprecated

Community
  • 1
  • 1
harshitpthk
  • 4,058
  • 2
  • 24
  • 32