当前位置:编程学习 > JAVA >>

android post请求超时

求解答:为什么在超时的情况下 得不到null;呢

public static String getPost(String url, Map<String, Object> params) {

HttpResponse httpResponse = null;
int statusCode = 0;
StringBuffer stringBuffer = null;
String result = null;
// Map<String,Object> map = new HashMap<String, Object>();
try {
String keycode = AppContext.getMD5FromStr(AppConfig.MD5_KEY
+ "hasNetwork");
params.put("action", "hasNetwork");
params.put("keycode", keycode);
Log.i("000000000009", String.valueOf(params));
HttpParams httpParameters1 = new BasicHttpParams();
// 超时设置
HttpConnectionParams
.setConnectionTimeout(httpParameters1, 5 * 1000);
HttpConnectionParams.setSoTimeout(httpParameters1, 5 * 1000);

DefaultHttpClient client = new DefaultHttpClient(httpParameters1);
HttpPost post = new HttpPost(url);
List<NameValuePair> ls = new ArrayList<NameValuePair>();
Set<String> keys = params.keySet();
Log.i("000000007", String.valueOf(keys));
for (String key : keys) {
ls.add(new BasicNameValuePair(key, params.get(key).toString()));
Log.i("000000000010", String.valueOf(params.get(key)));
}

post.setEntity(new UrlEncodedFormEntity(ls, HTTP.UTF_8));
httpResponse = client.execute(post);
statusCode = httpResponse.getStatusLine().getStatusCode();
Log.i("0000000000011", String.valueOf(statusCode));
if (statusCode == 200) {
Log.i("0000000000011", "555555555555555");
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpResponse.getEntity());
}
Log.i("gggggggggggggggggg", result);
return result;

} catch (UnsupportedEncodingException e1) {
Log.i("00000001", "lianjieshibai");
} catch (ClientProtocolException e1) {
Log.i("00000002", "lianjieshibai");
} catch (IOException e1) {
Log.i("00000003", "lianjieshibai");
} catch (IllegalStateException e) {
Log.i("00000004", "lianjieshibai");
}
return null;
} android
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,