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?

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

You must assign the parameters to the HttpClient.

Please see this post;

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.