Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send login/password info to a website thru application?  RSS feed

 
Adithya Rayaprolu
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an application in which I am connecting to a particular website using java.net.URL class, which requires login/password information. I am using openStream method of URL class, how to send login/password information to this, so I can access any other page from that site?
Thanks a lot in advance.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adithya,
First off, you don't want to open the raw stream with URL.openStream(). Instead call URL.openConnection() and get an URLConnection.
The login should go something like this:

Now you'll have to write the method base64Encode(String input). If you are not familiar with Base64 encoding, you can learn about it here:RFC 2045.
Hope this helps,
Michael Morris
Damn Smileys!!
[ March 07, 2003: Message edited by: Michael Morris ]
[ March 07, 2003: Message edited by: Michael Morris ]
[ March 07, 2003: Message edited by: Michael Morris ]
 
Adithya Rayaprolu
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,
Thanks for the reply. It helped. Is there a way that I can accept cookies thru java application? Can you please tell me how to do it?
Thanks once again in advance.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adithya,

Is there a way that I can accept cookies thru java application?

Yep, but it ain't no cake walk thru an URLConnection. If you want to pursue it, I would refer you to RFC 2109 which abstracts the HTTP State Management Mechanism or cookies. Also, look at the API docs on URLConnection especially the getHeaderFieldXXX methods.
I would like to also let you know that there is (or was, I'm not totally sure about 1.4) an undocumented Base64 encoder in Java 2: sun.misc.Base64Encoder. You can get an encoded String with:

Michael Morris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!