1

Timeout does not seem to work in async class

int timeoutConnection = 3000;
url=urls[0].getUrl();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urls[0].getUrl());
HttpConnectionParams.setConnectionTimeout(httppost.getParams(), timeoutConnection);
int timeoutSocket = 3000;
HttpConnectionParams.setSoTimeout(httppost.getParams(), timeoutSocket);
httppost.setEntity(new UrlEncodedFormEntity(urls[0].getParameters()));
// Execute HTTP Post Request
HttpResponse responsePOST = httpclient.execute(httppost);
resEntity = responsePOST.getEntity();
response=EntityUtils.toString(resEntity);

Please help me how I can set time out in AsyncTask class?

Oleg Estekhin
  • 8,063
  • 5
  • 49
  • 52
user2624301
  • 249
  • 1
  • 2
  • 7

2 Answers2

0

Try this

// Set connection timeout
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httppost.getParams(), timeoutConnection);
// set socket timeout
int timeoutSocket = 3000;
HttpConnectionParams.setSoTimeout(httppost.getParams(), timeoutSocket);

// Create the client
HttpClient httpclient = new DefaultHttpClient();
url=urls[0].getUrl();

// Create the post
HttpPost httppost = new HttpPost(urls[0].getUrl());
httppost.setEntity(new UrlEncodedFormEntity(urls[0].getParameters()));
// Execute HTTP Post Request and get response
HttpResponse responsePOST = httpclient.execute(httppost);
resEntity = responsePOST.getEntity();
response=EntityUtils.toString(resEntity);
Community
  • 1
  • 1
ngrashia
  • 9,869
  • 5
  • 43
  • 58
  • Have you checked the link? That is slightly different. Also, try setting the values from 3000 to say 15000 and check if it is working. Then may be the time can be reduced. – ngrashia Jun 17 '14 at 07:03
0

You must assign the parameters to the HttpClient.

Please see this post;

https://stackoverflow.com/a/1565243/233048

Community
  • 1
  • 1
mach
  • 8,315
  • 3
  • 33
  • 51