Eric Giang

Greenhorn
+ Follow
since Aug 13, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Eric Giang

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);