代码如下:
public class test {
public static void main(String[] args) throws Exception {
URL url = new URL("https://play.google.com/……e");
URLConnection connection = url.openConnection();
connection.connect();
InputStream inputstr = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputstr,"utf-8"));
String s = null;
int temp = 0;
while( ( s = br.readLine()) != null){
System.out.println(s);
}
}
}
报错如下:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at test.main(test.java:14)
前几天还能跑的程序,最近突然就不能跑了,而且除了谷歌的这个网页,其他的网页都能抓,求大神帮助啊!谢谢!!
------解决方案--------------------
你这是https的链接,没见你指定端口,而且https是需要证书的,你这样写应该是不行的
试试apache的httpclient那个库吧