• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic