Hi
I am trying to open a web page using HttpURLConnection. I was getting ConnectExecption. I thought may be this is because I am behind a proxy.
I tried using a couple of approaches.. some of them from a
thread on javaranch itself.
This is the code that i tried using... i provided proper values to
systemSettings.put("http.proxyHost","myproxy.com") ;
systemSettings.put("http.proxyPort", "80") ;
Still m left with the refused connection.
Please help!! Thanks
import java.util.*;
import java.io.*;
import java.net.*;
public class crawler {
public static void main(
String args[]) {
try {
//First set the Proxy settings on the System
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","myproxy.com") ;
systemSettings.put("http.proxyPort", "80") ;
URL yahoo = new URL("http://www.yahoo.com");
HttpURLConnection con = (HttpURLConnection) yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
while ( (inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
me.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}