如何设置android HttpPost 连接服务器超时
16lz
2021-01-25
之前试了几种方法都没能成功,此处忽略,最后还是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);
更多相关文章
- 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
- Android(安卓)解决监听home键的几种方法
- android binder相关
- Android(安卓)使用 kotlin 协程
- android 利用path 实现手写板的手写效果
- 【Android(安卓)开发教程】使用Intent调用内置应用程序
- ButterKnife--View注入框架
- android 顶部横向滑动菜单效果
- Android(安卓)中使用 ServiceLoader、AutoService 摔坑记录