• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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);
 
That is a really big piece of pie for such a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic