I have been fighting with proxy issues for some time and finally solved
it. Originally I was doing the following...
String url = "http://www.goodhost.com:80",
proxy = "64.202.165.130",
port = "3128";
URL server = new URL(url);
System.getProperties().put("http.proxySet","true");
System.getProperties().put("http.proxyHost",proxy);
System.getProperties().put("http.proxyPort",port);
HttpURLConnection conn = (
HttpURLConnection)server.openConnection();
conn.connect();
But the proxy was never used. I always got a security exception on
"www.goodhost.com" and changing the proxy to be invalid did not cause
any error. So I went down to the http level and it worked....
URL server = new URL(url);
Socket socket = new Socket(proxy,port);
Writer writer = new OutputStreamWriter(socket.getOutputStream(),
"US-ASCII");
writer.write("GET " + server.toExternalForm() + " HTTP/1.0\r\n");
writer.write("Host: " + server.getHost() + "\r\n\r\n");
So my question, is "Why doesn't the http.proxySet work? Why do I have
to manage the http myself? Im running java 1.5.0_07 in Tomcat. I would
really rather not do the HTTP myself.
-Robert
EJP - 11 Nov 2006 00:34 GMT
> So my question, is "Why doesn't the http.proxySet work?
I think you have a wider problem but FYI that particular property has
never done anything in the JDK. It existed in the short-lived HotJava
bean and a number of well-meaning authors put it into their books. It
does nothing whether set true, false, blue, green, grue, ...
Arne Vajhøj - 11 Nov 2006 01:03 GMT
> System.getProperties().put("http.proxySet","true");
> System.getProperties().put("http.proxyHost",proxy);
> System.getProperties().put("http.proxyPort",port);
> But the proxy was never used. I always got a security exception on
> "www.goodhost.com" and changing the proxy to be invalid did not cause
> any error.
System.setProperty("http.proxyHost", proxy);
System.setProperty("http.proxyPort", port);
has worked for me.
Does your proxy server requires authentication ?
Arne