Skip to Main Content

Java Programming

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!

Java proxy - http.nonProxyHosts issue

881499Aug 10 2011 — edited Aug 12 2011
Hi,
I have a test code that connects to a URL. I want the local URLs to be connected without proxy server. But It ends with the following error
C:\temp>java -Dhttp.nonProxyHosts="192.168.10.150|*.mycompany.local|localhost" ProxyTest
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy.
Proxy returns "HTTP/1.0 403 Forbidden"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnec
tion.java:1648)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:164)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1172)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Http
sURLConnectionImpl.java:234)
at ProxyTest.main(ProxyTest.java:17)

The following is my code

import java.net.*;
import java.io.*;

public class ProxyTest
{
public static void main(String[] args) throws Exception
{
System.setProperty("nonProxyHosts", "192.168.10.150|localhost");
Authenticator.setDefault(new ProxyAuth("pandian", "pandian"));

URL url = new URL("https://192.168.8.150/");

SocketAddress addr = new InetSocketAddress("192.168.8.100", 808);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);

HttpURLConnection con = (HttpURLConnection) url.openConnection(proxy);
InputStream is = con.getInputStream();
int i=-1;
while ((i=is.read())!=-1)
{
System.out.print((char)i);
}
is.close();

}
}

class ProxyAuth extends Authenticator
{
private String user, password;

public ProxyAuth(String user, String password) {
this.user = user;
this.password = password;
}

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
};


The same code executes for any URLs those are not blocked by the proxy server.

Any guess?

Edited by: user3749193 on Aug 10, 2011 2:40 AM

Edited by: user3749193 on Aug 10, 2011 3:18 PM
This post has been answered by EJP on Aug 10 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 9 2011
Added on Aug 10 2011
11 comments
14,797 views