INFO 2008-01-03 11:10:08,656 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:20,906 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:20,906 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:24,515 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:24,515 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:25,625 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:25,625 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:26,328 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:26,328 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:28,546 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:28,546 org.apache.commons.httpclient.HttpMethodDirector - Retrying request我用多线程抓取网页就出现这个。请问怎么解决了。基本一开线程就无法使用。谢谢
INFO 2008-01-03 11:10:20,906 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:20,906 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:24,515 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:24,515 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:25,625 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:25,625 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:26,328 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:26,328 org.apache.commons.httpclient.HttpMethodDirector - Retrying request
INFO 2008-01-03 11:10:28,546 org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
INFO 2008-01-03 11:10:28,546 org.apache.commons.httpclient.HttpMethodDirector - Retrying request我用多线程抓取网页就出现这个。请问怎么解决了。基本一开线程就无法使用。谢谢
2 对方发现有扒手,拒绝提供。 类似QQ的图片空间。3 你测试抓取 sina 的新闻看看。 如果能用,程序就没问题啦!
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
/**
*最简单的HTTP客户端,用来演示通过GET或者POST方式访问某个页面
*@authorLiudong
*/public class SimpleClient {
public static void main(String[] args) throws IOException
{
HttpClient client = new HttpClient();
// 设置代理服务器地址和端口 //client.getHostConfiguration().setProxy("proxy_host_addr",proxy_port);
// 使用 GET 方法 ,如果服务器需要通过 HTTPS 连接,那只需要将下面 URL 中的 http 换成 https
HttpMethod method=new GetMethod("http://finance.sina.com.cn/chanjing/b/20080415/07584749699.shtml");
//使用POST方法
//HttpMethod method = new PostMethod("http://java.sun.com");
client.executeMethod(method); //打印服务器返回的状态
System.out.println(method.getStatusLine());
//打印返回的信息
System.out.println(method.getResponseBodyAsString());
//释放连接
method.releaseConnection();
}
}
异常如下:13:12:38,484 INFO HttpMethodDirector:434 - I/O exception caught when processing request: finance.sina.com.cn
13:12:38,484 INFO HttpMethodDirector:440 - Retrying request
13:12:38,484 INFO HttpMethodDirector:434 - I/O exception caught when processing request: finance.sina.com.cn
13:12:38,484 INFO HttpMethodDirector:440 - Retrying request
13:12:38,484 INFO HttpMethodDirector:434 - I/O exception caught when processing request: finance.sina.com.cn
13:12:38,484 INFO HttpMethodDirector:440 - Retrying request
Exception in thread "main" java.net.UnknownHostException: finance.sina.com.cn
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at myhttpclient.SimpleClient.main(SimpleClient.java:22)
要是的把代理配好。
client.getHostConfiguration().setProxy("代理的ip地址",代理的端口);
如:client.getHostConfiguration().setProxy("192.168.0.254",80);我们公司代理上网的程序里不配代理我也连不上,程序里配置了代理才可以。