Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URLConnection setRequestProperty doesn't seem to work

843790Jan 21 2010 — edited May 21 2010
G'day, I am trying to set a URLConnection property for proxy authentication. Here's a simple test I've created:
import java.net.*;

public class ProxyTest {
    public static void main(String[] args) {
        try {
            System.setProperty("http.proxyHost", "192.168.107.24");
            System.setProperty("http.proxyPort", "3128");
            URL url=new URL("http://google.com");
            URLConnection uc = url.openConnection ();
            uc.setRequestProperty( "Proxy-Authorization", "foobar");
            System.out.println("Proxy-Authorization is: " + uc.getRequestProperty("Proxy-Authorization"));
            uc.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
This always gives my "Proxy-Authorization is null". I have tested this on java 1.6 and 1.5, on a linux system and a windows xp system. In my real app the url connection always gives me 407 unauthorized, I have used tcpdump to check just in case the Proxy-Authorization is being sent, but it isn't.

I am probably missing something simple - can anyone see what it might be? Cheers.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2010
Added on Jan 21 2010
2 comments
779 views