• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invoking URL through Proxy Connection

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic