Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help needed for connecting thru a proxy

1 view
Skip to first unread message

Amy Sun

unread,
Oct 4, 1997, 3:00:00 AM10/4/97
to

Hi, I'm writing some java code that needs access to (i.e. read contents of)
external web pages. Our company sits behind a firewall. I read from this
newsgroup one way to get around it is to set system properties "proxySet",
"proxyHost", and "proxyPort". But somehow it still doesn't work for me when
my url points to an external page; I would get an "UnknownHostException."
I attached my test code and output below. If any of you has a clue of what
I did wrong, I would really appreciate your help. You can reach me at
amy...@boeing.com.

Thanks and regards,
Amy

/* TestProxy.java */
import java.io.*;
import java.net.*;
import java.util.*;

public class TestProxy
{
public static void main(String args[])
{
Properties prop = System.getProperties();
prop.put("proxySet", "true");
prop.put("proxyHost", "http://www-blv-proxy.boeing.com");
prop.put("proxyPort", "31060");

try

URL url = new URL(args[0]);
URLConnection conn = url.openConnection();

BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;

while ((line = reader.readLine()) != null)
System.out.println(line);
reader.close();
}
catch (MalformedURLException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}

C:\test>java TestProxy http://www.yahoo.com
java.net.UnknownHostException: www.yahoo.com
at java.net.InetAddress.getAllByName0(InetAddress.java:479)
at java.net.InetAddress.getByName(InetAddress.java:355)
at java.net.Socket.<init>(Socket.java:97)
at sun.net.NetworkClient.doConnect(NetworkClient.java:62)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:267)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:329)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:210)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:218)
at sun.net.www.http.HttpClient.New(HttpClient.java:229)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:2
35)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:315)
at TestProxy.main(TestProxy.java:19)

// the end


0 new messages