Forums Register Login

connecting to the web by a JAVA program

+Pie Number of slices to send: Send
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"...
+Pie Number of slices to send: Send
Is your machine set to use the proxy server as the gateway?
If the machine is set to use the proxy server as the gateway and the proxy server does the work of connecting to the router you are going to have to deal with giving credentials.
If your machine is set to use the real gateway / router as its gateway, and your browsers are set to use the proxy server (as a proxy ;-) then you might be able to get away with not using use credentials.
If this was way over your head post to say so and Ill explain a bit better ;-)
+Pie Number of slices to send: Send
Dear Friend,
As u said, i am in the same set up. could u pl. advice me further in the code wise...
pl. my dear pal.
waiting for ur kind reply,
Geetha C.

Originally posted by Karl Laird:
Is your machine set to use the proxy server as the gateway?
If the machine is set to use the proxy server as the gateway and the proxy server does the work of connecting to the router you are going to have to deal with giving credentials.
If your machine is set to use the real gateway / router as its gateway, and your browsers are set to use the proxy server (as a proxy ;-) then you might be able to get away with not using use credentials.
If this was way over your head post to say so and Ill explain a bit better ;-)

 
+Pie Number of slices to send: Send
Dear Friend,
As u said, i am in the same set up. could u pl. advice me further in the code wise...
pl. my dear pal.
waiting for ur kind reply,
Geetha C.

Originally posted by Karl Laird:
Is your machine set to use the proxy server as the gateway?
If the machine is set to use the proxy server as the gateway and the proxy server does the work of connecting to the router you are going to have to deal with giving credentials.
If your machine is set to use the real gateway / router as its gateway, and your browsers are set to use the proxy server (as a proxy ;-) then you might be able to get away with not using use credentials.
If this was way over your head post to say so and Ill explain a bit better ;-)

 
+Pie Number of slices to send: Send
This thread has been cross-posted in Sockets and Internet Protocols, so I am closing this one. Please refer to the other posting to continue this topic.
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 1303 times.
Similar Threads
Connection Refused Exception
Problems with Struts in WebSphere 5.0: UnknownHostException
Http through Firewall/Proxy
connecting to the web by a JAVA program
how to read files from internet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:20:53.