Я использую Java-класс GetURL.java, который берет URL-адрес и возвращает HTML-код этой страницы, однако я продолжаю получать следующий вывод при попытке определенного URL-адреса:
Reading URL: https://artifactory.somewhere.com/artifactory/webapp
url.getHost: artifactory.somewhere.com
Socket Inet Address: artifactory.somewhere.com/XX.XXX.XX.XX
https://artifactory.somewhere.com/artifactory/webapp is reachable: false
HTTP URL Connection (huc) is using a proxy: false
Can not connect
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:208)
at java.net.SocketInputStream.read(SocketInputStream.java:134)
at com.ibm.jsse2.a.a(a.java:227)
at com.ibm.jsse2.a.a(a.java:269)
at com.ibm.jsse2.qc.a(qc.java:459)
at com.ibm.jsse2.qc.h(qc.java:275)
at com.ibm.jsse2.qc.a(qc.java:541)
at com.ibm.jsse2.qc.startHandshake(qc.java:89)
at com.ibm.net.ssl.www2.protocol.https.c.afterConnect(c.java:173)
at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:63)
at com.ibm.net.ssl.www2.protocol.https.b.connect(b.java:96)
at GetURL.getURL(GetURL.java:45)
at GetURL.main(GetURL.java:78)
Java-класс:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.net.Socket;
/**
* Chapter 2 Example
*
* This program uses the standard Java URL class to open a connection to a web
* page and download the contents.
*
* @author Jeff Heaton
* @version 1.0
*/
public class GetURL {
/**
* This method will display the URL specified by the parameter.
*
* @param u
* The URL to display.
*/
static protected void getURL(String u) {
URL url;
InputStream is;
InputStreamReader isr;
BufferedReader r;
String str;
try {
System.out.println("Reading URL: " + u);
url = new URL(u);
System.out.println("url.getHost: " + url.getHost());
Socket clientSocket = new Socket(url.getHost(), 443);
System.out.println("Socket Inet Address: " + clientSocket.getInetAddress());
Boolean canReachClient = clientSocket.getInetAddress().isReachable(5 * 1000);
System.out.println(u + " is reachable: " + canReachClient);
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
HttpURLConnection.setFollowRedirects(true);
huc.setConnectTimeout(5 * 1000);
huc.setRequestMethod("GET");
System.out.println("HTTP URL Connection (huc) is using a proxy: " + huc.usingProxy());
huc.connect(); // problem is HERE!!!!
is = huc.getInputStream();
isr = new InputStreamReader(is);
r = new BufferedReader(isr);
do {
str = r.readLine();
if (str != null)
System.out.println(str);
} while (str != null);
} catch (MalformedURLException e) {
System.out.println("Must enter a valid URL");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Can not connect");
e.printStackTrace();
}
}
/**
* Program entry point.
*
* @param args
* Command line arguments. Specified the URL to download.
*/
static public void main(String args[]) {
if (args.length < 1)
System.out.println("Usage: GetURL [url]");
else
getURL(args[0]);
}
}
Мне удалось определить, что ошибка возникает при вызове huc.connect();
, но не могу выяснить причину.
Я использую jdk1.7.1_64-ibm, и он работает, как и ожидалось, с другими HTTPS-адресами
Заранее благодарен за любую помощь