aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Accessing secured websites through java URL/Socket program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Accessing secured websites through java URL/Socket program" Watch "Accessing secured websites through java URL/Socket program" New topic
Author

Accessing secured websites through java URL/Socket program

Biswajit Biswal
Greenhorn

Joined: Mar 14, 2006
Posts: 3
Hi,

I am working on an intranet search engine using java URL and Authenticator class. This is a secured web-site using SSL in http server. I am not able to access the password protected pages. Following is the code:

URL url = new URL("https://*************");
URLConnection connection = url.openConnection();
PasswordAuthentication pa = Authenticator.requestPasswordAuthentication( InetAddress.getByName(connection.getURL().getHost()),
connection.getURL().getPort(), connection.getURL().getProtocol(), null, "Basic");
StringBuffer buf = new StringBuffer("*****************");
buf.append(":");
buf.append("************");
String encoded = new sun.misc.BASE64Encoder().encode(buf.toString().getBytes());
connection.setRequestProperty ("Authorization", "Basic" + encoded);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}

Let me know if there is any other alternative

tnx,
Biswajit Biswal
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
I am not able to access the password protected pages.

What does this mean? Are there any error messages or exceptions? If so, which ones, and in which lines do they occur?


Ping & DNS - updated with new look and Ping home screen widget
Biswajit Biswal
Greenhorn

Joined: Mar 14, 2006
Posts: 3
There was no error as such. I was not able to login to the site using the mentioned code. So, everytime I was getting the login page, even though I tried to access the inside pages.

tnx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing secured websites through java URL/Socket program
 
Similar Threads
url connection: IOException-socket closed
inserted data lost!
Reading remote file using URL through web application
invoking a servlet from client Java code
How do I avoid IllegalState when calling getReader in chain?