Discussions

General J2EE: JSSE: Proxy Authentication Required

  1. JSSE: Proxy Authentication Required (4 messages)

    I ALWAYS get the error "java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required". I've tried several suggestions that I got from the java forums and I still can't get it to work.

    Here's my code. Thanks for any help.

    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import java.security.Security;

    public class URLReader {
        public static void main(String[] args) throws Exception {

    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

    Properties properties = System.getProperties();
    properties.put("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    properties.put("https.proxyHost","myWebHost");
        properties.put("https.proxyPort","80");
       
        URL url = new URL("https://www.verisign.com");
        URLConnection connection = url.openConnection();
        
    String authString = "myUsername:myPassword";
    String encodedAuthString =
    "Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
    encodedAuthString = "Basic";
    connection.setUseCaches(false);
    connection.setRequestProperty("Proxy-authorization", encodedAuthString);

    BufferedReader in = new BufferedReader(
    new InputStreamReader( connection.getInputStream()));

    String inputLine;

    while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);

    in.close();
        }
    }
  2. Hi,
    Try setting these system properties that enable SOCKS proxying for java sockets:
    socksProxyHost=<your socks server IP>
    socksProxyPort=1080 (or your socks server port).
    Best regards, Mircea
  3. Is there a reason why you create the encodedAuthString, and then over write it with "Basic"?

     String encodedAuthString =
    "Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
    encodedAuthString = "Basic";

    I bet you didn't intend on having that second line there.
  4. Hi Mircea, thanks for your suggestion. I tried it out and I get a "java.net.ConnectionException: Connection refused" error. And I don't think I wanna use a SOCKS proxy anyway, cuz everything here (browser, Yahoo Messenger, etc. all use HTTP proxy).

    Thanks Scott for pointing that out. I actually put it there just recently while I was just doing some debugging. I took it out already and the program still stubbornly insists on not working.

    ANy other suggestions?
  5. Actually, it has just come to my attention that all the URL's that I will be accessing all exist within the intranet. So I guess I won't need to pass the firewall after all.

    It's strange though that I never was able to pass the firewall with my code above. Thanks anyway for your help guys!

    Regards,
    Liam