网上拷贝了一段给你,看是不是你想要的:1,设置get方法请求超时为 5 秒Java代码
GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);
Java代码
GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000); GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);
2,设置 Http 连接超时为5秒Java代码
HttpClient httpClient=new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
Java代码
<SPAN class=hilite1>HttpClient</SPAN> <SPAN class=hilite1>httpClient</SPAN>=new <SPAN class=hilite1>HttpClient</SPAN>();
<SPAN class=hilite1>httpClient</SPAN>.getHttpConnectionManager().getParams().setConnectionTimeout(5000); HttpClient httpClient=new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
设置连接超时和请求超时,这两个超时的意义不同,需要分别设置。
GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);
Java代码
GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000); GetMethod getMethod=new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);
2,设置 Http 连接超时为5秒Java代码
HttpClient httpClient=new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
Java代码
<SPAN class=hilite1>HttpClient</SPAN> <SPAN class=hilite1>httpClient</SPAN>=new <SPAN class=hilite1>HttpClient</SPAN>();
<SPAN class=hilite1>httpClient</SPAN>.getHttpConnectionManager().getParams().setConnectionTimeout(5000); HttpClient httpClient=new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
设置连接超时和请求超时,这两个超时的意义不同,需要分别设置。
解决方案 »
- 修改了frameworks/base/core/res/res/drawable下的xml文件,但是不知道如何快速编译
- android远程连接mysql数据库
- 新手:ProgressDialog
- android 怎么点击出现,出现 “请稍后。。” ,当加载完后消失
- 关于intent广播的问题?
- Android中如何从一个EditText跳转到另一个EditText
- android 4.0.3 模拟器,不能打印应用层调试信息,有什么办法解决?
- 请教高手高手高高手一个有关BLCR的问题!!!!!
- 关于Android调用GPS遇到的问题,大神请戳入
- 有关mtk last_kmsg log没有内容事宜
- Android项目预研的总结
- 怎么让键盘出来的时候背景不压缩?
httpUrlConnection.setConnectTimeout(int timeout) Sets the timeout value in milliseconds for establishing the connection to the resource pointed by this URLConnection instance.还有一个是读取信息超时的:
setReadTimeout(int timeout) Sets the timeout value in milliseconds for reading from the input stream of an established connection to the resource.