• 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

Java: entering a secure website with userid and password

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to use Java to enter a secure website that requests username and password. How do we even go about posting the userid and password.

I found smthg like this:
String parameters = URLEncoder.encode("inst").concat("=").concat(
URLEncoder.encode(inst));
URL url = new URL("https://jdfg?"+parameters);
HttpsURLConnection urlc = null;
urlc = (HttpsURLConnection) url.openConnection();
urlc.setRequestProperty("Content-Type","Text/xml; charset=\"utf-8\"");
urlc.setRequestMethod("POST");
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setUseCaches(false);
OutputStreamWriter outStream = new OutputStreamWriter(new BufferedOutputStream(urlc.getOutputStream()),"ASCII");
System.out.println("Query String"+parameters);
outStream.write(parameters);
outStream.flush();
outStream.close();
urlc.setRequestProperty("Content-Type", "text/html");
urlc.connect();

//get response
InputStream is = urlc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
System.out.println(urlc.getResponseMessage());
//reading the response recieved
String response = System.getProperty("line.separator")+ br.readLine();
System.out.println(response);

If I try to exceute the same piece of code by appending paramters to the URL after the ? ,everything works fine.
URL url = new URL("https://sdfsdg?"+parameters);
 
reply
    Bookmark Topic Watch Topic
  • New Topic