This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Connect to password protected sites Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Connect to password protected sites" Watch "Connect to password protected sites" New topic
Author

Connect to password protected sites

Marton Istvan
Greenhorn

Joined: May 02, 2009
Posts: 3
hi all!

I want to connect some sites with username and password. I have been looking for the solution a few days but I can't find it. I found some useful information, but i can't solve the problem.

Here is one example, the others are similar. (with other sites)

There is one forum : logintest.forumotion.com
and a topic protected by username and password : http://logintest.forumotion.net/your-first-forum-f1/testtopic-1-t2.htm

If you have an account (you're a member), you can see the topic. I have registered, i have an account. (I'm the admin in that forum, I made it)
Here is the code which I'm trying



Every time when I try it, I can't get the source of the topic. I get a login page source. What's the problem with it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Welcome to JavaRanch.

That page doesn't use Basic Authentication (which is what your code does), it uses form authentication. You'll need to post the account info to the proper URL, after which a cookie will probably be set which must then be sent in all subsequent page accesses.

I recommend to use a library like jWebUnit (or HtmlUnit) for programmatic access to web sites; that's generally simpler than using the URL and URLConnection classes.


Ping & DNS - my free Android networking tools app
Marton Istvan
Greenhorn

Joined: May 02, 2009
Posts: 3
thanks! I'll try it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect to password protected sites
 
Similar Threads
how to use HTTPUrlConncection with user and password
HTTP authentication - can't figure it out!
java.io.IOException: Server returned HTTP response code: 401 for URL:
Attempt to retrieve Sharepoint WSDL fails with “Server redirected too many times”
Problem using XmlRpc with SSL in web browser