Java http proxy SocketException: неожиданный конец файла с сервера. Сброс подключения. - PullRequest
0 голосов
/ 10 января 2019

Я использую URL доступа java.net.Proxy. В Windows все в порядке, но в Centos есть java.net.SocketException

Я пробовал много версий Centos / JDK, всегда исключение.

public static void main(String[] args) throws Exception {       
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("220.179.210.135", 45761));
    URL url = new URL("https://www.baidu.com/");
    URLConnection conn = null;
    if (args.length == 0) {
        System.out.println("is proxy");
        conn = url.openConnection(proxy);
    } else {
        conn = url.openConnection();
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) {
        System.out.println(inputLine);
    }
    in.close();
}

Исключение

Exception in thread "main" java.net.SocketException: Unexpected end of file from server
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
        at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2055)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
        at HttpProxy.main(HttpProxy.java:27)
...