网上拷贝了一段给你,看是不是你想要的: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);
设置连接超时和请求超时,这两个超时的意义不同,需要分别设置。
解决方案 »
- 改动布局XML文件后一运行就forced Close,请帮看看有什么问题?
- 跪求大神帮助,我在Android项目里面给button进行SetText的时候一直报错NulPointerException
- android 应用层 如何 发送at命令
- 为什么我在activity中发intent给broadcastreceiver,却接收不到
- android新手问题送分了(结贴率100%)
- 关于android的奇怪问题
- 感谢这位zcpangzi朋友帮我解决了Android安装的问题,我把问题总结了一下特此分享给像我一样正在学习中的新手!
- listview的setselection为何失效
- 命令/mnt/sdcard/monkey.log 2>&1 &中的&什么意思
- android入门级问题
- 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.