I am trying to open a URL and read the website line by line. I can do this fine in Eclipse because I guess Eclipse configures it automatically for you. When I try to run the program from the command line the program hangs and never reads the URL.
After some research the problem has to do with the proxy settings, I figured out. All articles I come across say to change something like this:
System.setProperty("java.net.useSystemProxies","true");
Or to add lines of code like this:
System.setProperty("http.proxyHost", "webcache.mydomain.com");
System.setProperty("http.proxyPort", "80");
But I have no idea what to put for my proxy settings and what any of those System.setProperty
calls do. Does anyone know how to set the proxy settings? I am just trying to run this from my home computer on a localhost and I'm not even behind a proxy or anything.
Here is the code I use that works fine in Eclipse.
URL link = new URL("http://www.yahoo.com");
BufferedReader in = new BufferedReader(new InputStreamReader(link.openStream()));
//InputStream in = link.openStream();
String inputLine = "";
int count = 0;
while ((inputLine = in.readLine()) != null) {
site = site + "\n" + inputLine;
}
in.close();
java -Dhttp.proxyHost=proxyhostURL
-Dhttp.proxyPort=proxyPortNumber
-Dhttp.proxyUser=someUserName
-Dhttp.proxyPassword=somePassword javaClassToRun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With