• 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

connecting to the web by a JAVA program

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
My machine is connected to the net through a proxy server. The proxy server we are using is "squid proxy". Here in the said proxy, the users who browse the net are restricted through the user id and password. So, if i want to open www.rediff.com site, in my WEB BROWSER, i have to provide the user id and password and then only, i can browse the site....here i am trying to connect to the rediff site by my below said JAVA program...i am getting an error of:
"
Exception in thread "main" java.net.UnknownHostException: www.rediff.com
at java.net.InetAddress.getAllByName0(InetAddress.java:574)
at java.net.InetAddress.getAllByName0(InetAddress.java:543)
at java.net.InetAddress.getByName(InetAddress.java:452)
at java.net.Socket.<init>(Socket.java:98)
at sun.net.NetworkClient.doConnect(NetworkClient.java:54)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:320)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:431)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:260)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:270)
at sun.net.www.http.HttpClient.New(HttpClient.java:282)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:3
71)
at testing.main(squid.java:13)"
What i guess is, since the proxy restricts the users, i am getting the said error...Is is correct??? if so, how can i proceed further to contact the rediff site...thru my below said JAVA program....
pl. suggest me...
bye,
Sakthivel S.
import java.io.*;
import java.net.*;
public class testing
{
public static void main(String args[]) throws Exception
{
URL theurl = new URL("http://www.rediff.com");
HttpURLConnection hurl = (HttpURLConnection)(theurl.openConnection());
hurl.setUseCaches(false);
hurl.setDoInput(true);
hurl.setDoOutput(true);
hurl.connect();
hurl.disconnect();
hurl=null;
}
}
P.S: the people are restricted via the proxy server...I mean, I have to provide my userid and password, while browsing the net, through the Web Browser. So, I am in a doubt of "whether through my JAVA program also, I have to get authenticated from the proxy server or no needed"...
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This really isn't a web services problem. I'm moving this to the networking forum.
Kyle
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately gc had posted the question here as well (tssk, tssk) so I've zapped the duplicate.
On to your regularly scheduled answers... you're not even resolving the hostname i.e. you don't have DNS. I think the proxy can handle the domain name lookup for for you but I'm a bit blurry on this.
To tell the JDK to use a proxy, set the http.proxyHost and http.proxyPort system parameters (either programmatically or using the JVM -d flag). For proxy authentication, look into setting up a java.net.Authenticator (use Authenticator.setDefault to install one).
- Peter
 
geetha chandran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear PAL,
could u pl. be a bit clear by the code wise...
waiting for ur kind reply,
Geetha C.

Originally posted by Peter den Haan:
Unfortunately gc had posted the question here as well (tssk, tssk) so I've zapped the duplicate.
On to your regularly scheduled answers... you're not even resolving the hostname i.e. you don't have DNS. I think the proxy can handle the domain name lookup for for you but I'm a bit blurry on this.
To tell the JDK to use a proxy, set the http.proxyHost and http.proxyPort system parameters (either programmatically or using the JVM -d flag). For proxy authentication, look into setting up a java.net.Authenticator (use Authenticator.setDefault to install one).
- Peter

 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most naive implementation possible, but probably adequate:
- Peter
 
geetha chandran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I want to set the Default Authenticator permission, using my policy tool. I dont know how to set the above said....I went to my command prompt and typed as policytool. It opened a new window called as "Policy Tool", with an alert error message as "Could not find Policy File : C:\WINNT\Profiles\machine001\.java.policy"....pl. advice me for setting a policy tool...
waiting for ur reply,
Geetha C.

P.S: I am trying to set this policy tool to get my java program get default authentication from my proxy, which expects the authentication, from each and every user, who browses the net through the proxy server....
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The setDefaultAuthenticator NetPermission has to do with your ability to call setDefaultAuthenticator(). The policy tool will not help you in the actual setting up of an authenticator.
- Peter
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, if you are only trying to connect to rediff.com and are behind a proxy.
then try this command
java -Dhttp.proxyHost=yourproxyIP -Dhttp.proxyPort=yourproxyport yourclassfileName
Lupo
Well, for the default authenticator, create a new policy file and then set the params.
reply
    Bookmark Topic Watch Topic
  • New Topic