• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing secured websites through java URL/Socket program

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Biswajit Biswal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic