如何设置android HttpPost 连接服务器超时

之前试了几种方法都没能成功,此处忽略,最后还是stackoverflow拯救了我啊,上代码
// 根据内容来源地址创建一个Http请求
HttpPost request = new HttpPost(SERVER_URL); 
//设置请求超时
int timeoutConnection = 3 * 1000;
HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
//设置响应超时
int timeoutSocket = 5 * 1000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
// 发送请求并获取反馈
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse httpResponse = httpClient.execute(request); 

你可能感兴趣的:(android,超时,HttpPost)