0
URL url = new URL(urlStr);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

The second line throws java.net.UnknownHostException. I was in a internal network in my company, and I hope I can help another one who's also in the same internal network with me to visit the website, and I just want to read content from the URL and give the content to the client side, is there any one help me on this?

Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67

1 Answers1

0

Companys normally have a proxy server to the outside world. Try to configure the proxy data in a Proxy class and open the connection with proxy.

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(<ProxyUrl>,<ProxyPort>));
conn = new URL(urlString).openConnection(proxy);

If your proxy has a passwort authentication you have to set the log in data in an Authenticator:

Authenticator authenticator = new Authenticator() 
{

    public PasswordAuthentication getPasswordAuthentication() 
    {
        return (new PasswordAuthentication(<ProxyUser>,<ProxyPW>.toCharArray()));
    }
};
Authenticator.setDefault(authenticator);
NFoerster
  • 386
  • 2
  • 16
  • Hi Thorgas, Is the and comes from the url which I'm going to visit? – Wu Yang Michael Sep 24 '14 at 02:00
  • No, it's the Url & Port from the companys proxy server, which routes all the internet traffic from the internal company net to the outside net. Try to find the proxy configuration in your Browser(Firefox: Options -> Advanced -> Tab Network->Settings). But firefox is able to auto detect the proxy connection. You can also look and try this: http://superuser.com/questions/337685/how-do-i-change-the-windows7-lan-proxy-config-from-the-command-line – NFoerster Sep 24 '14 at 05:57
  • Thanks, but I can't find the proxy settings, here is the result of executing command "netsh winhttp show proxy" : Current WinHTTP proxy settings: Direct access (no proxy server). – Wu Yang Michael Oct 07 '14 at 09:29