超时似乎不适用于异步类
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);
请帮助我如何在AsyncTask
课程中设定时间?
答案 0 :(得分:0)
尝试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);
答案 1 :(得分:0)