• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking URL through Proxy Connection  RSS feed

 
somin bhuvan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to invoke url from java. I used the following code to do this:



URL url = null;

HttpURLConnection connection = null;

InputStream inStream = null;



Authenticator.setDefault(new UserAuthenticate("itlinfosys\\chaya_somanchi", "mypwd"));

System.out.println("After Authenticator");

String proxy_addr = "172.25.232.28";

int proxy_port = 80;

addr = new InetSocketAddress(proxy_addr,proxy_port);

System.out.println("After SocketAddress "+addr.toString());

System.out.println("Proxy Type: "+Proxy.Type.HTTP.toString());

proxy = new Proxy(Proxy.Type.HTTP, addr);

connection = (HttpURLConnection)url.openConnection(proxy);

connection.connect();

inStream = connection.getInputStream();

return inStream;





But there is some problem with Proxy.Type.HTTP. Its not showing any error or exception. In the console, it just stops after printing ´┐ŻAfter SocketAddress´┐Ż line. I have manually tested my proxy address and port in IE and they are correct(iam able to connect to internet using these).



Do let me know if you have any suggestions on this. Or it would be great if you have any other code to invoke a url. I just want to invoke a url like google.com and get the resultant html as an inputstream.



Thanks in advance.
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Proxy hosts and ports are set up using System.setProperty() or System.setProperties() methods. Here's a sample for setProperties()

Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "myProxyServer.com");
systemSettings.put("http.proxyPort", "80");
System.setProperties(systemSettings);

For https connections use the properties https.proxyHost and https.proxyPort

Set the system properties and then invoke your URLConnection code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!