如何设置android HttpPost 连接服务器超时
推荐于2016-03-09 · 知道合伙人影视综艺行家
关注
展开全部
1.// 根据内容来源地址创建一个Http请求
2.HttpPost request = new HttpPost(SERVER_URL);
3.//设置请求超时
4.int timeoutConnection = 3 * 1000;
5.HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
6.//设置响应超时
7.int timeoutSocket = 5 * 1000;
8.HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
9.// 发送请求并获取反馈
10.DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
11.HttpResponse httpResponse = httpClient.execute(request);
2.HttpPost request = new HttpPost(SERVER_URL);
3.//设置请求超时
4.int timeoutConnection = 3 * 1000;
5.HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
6.//设置响应超时
7.int timeoutSocket = 5 * 1000;
8.HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
9.// 发送请求并获取反馈
10.DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
11.HttpResponse httpResponse = httpClient.execute(request);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询