Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191993

Can't send request through SOCKS 4 proxy when using java.net.Proxy

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      1.8.0_131

      A DESCRIPTION OF THE PROBLEM :
      I use the java.net.Proxy to set the SOCKS proxy. In this case I always get the "Malformed reply from SOCKS server" exception when i try to send request through SOCKS v4 proxy.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.net.SocketException: Malformed reply from SOCKS server
      at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:129)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:459)
      at java.net.Socket.connect(Socket.java:589)
      at java.net.Socket.connect(Socket.java:538)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
      at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
      at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
      at com.test.Main.testJavaSocksProxy(Main.java:402)
      at com.test.Main.main(Main.java:146)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      SocketAddress addr = new InetSocketAddress("62.141.97.78", 33555);
      Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
      try {
                  URL url = new URL("https://google.com");
                  URLConnection conn = url.openConnection(proxy);
                  BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                  String inputLine;
                  while ((inputLine = in.readLine()) != null)
                      System.out.println(inputLine);
                  in.close();
      } catch (Exception e) {
                  e.printStackTrace();
      }
      ---------- END SOURCE ----------

        1. JI9051583.java
          1 kB
          Pallavi Sonal
        2. SocksServer.java
          17 kB
          Pallavi Sonal

            chegar Chris Hegarty
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: