Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting Web

Status
Not open for further replies.

Kadirpatel

Programmer
Mar 28, 2001
43
GB
Hi All,
I want to connect to the Web using URLConnection class. This is to be accomplished using core Java class. Can any body let me know how it is possible. Any link where I can get some example.
Thnaks.
 
Hi LittleWing,
The problem is that I want to make a search on the web. For that I want to connect to web using servlet. My site architecture is
HTML -----> Servlet
and servlet will do the searching job. So i want to know that how can i connect to web, using some Java class.
If the question is not clear please let me know, i'm ready to explain it once more.
Waiting for replies.
 
Hi Kadirpatel,

If I understood right, you want to connect to the certain Web page by using URLConnection.
Well, here is how URLConnection works:

URL url = new URL("URLaddress");
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true);
.
.
.
Then you can get Input- and OutputStreams by using URLConnection's
getInputStream() and getOutputStream() methods.

-Vepo
 
Thanks Vepo,
I'll definitely try it our and let you know. But i think that i'll also take care for Proxy. Isn't it ? I'll just check for that. But can u tell me that if i have to connect through proxy then what i should be doing.
Thanks.
 
Hi,

I haven't got much experiences about that, but you can check this example, it may help you:


I have connected trough proxy by using plain sockets, then HTTP-headers have to be added manually, like proxy redirect -address (like "POST /redirectAddress/ ....")


You may also need authentication if the proxy needs it. Then you may use java's BASE64Encoder to authenticate user:

String userPassword = theUsername + ":" + thePassword;
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());

URLConnection uc = url.openConnection();

uc.setRequestProperty ("Authorization", "Basic " + encoding);
 
Thanks Vepo for your reply. I'm working on it and think that it will help me a lot. Thanls again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top