Hi,
I'm currently trying to create a program that will log into the web page given to it if supplied with the user name and password.
but the problem im having is sending the POST request to the website and then retreiveing the URL it sends back to load in a web browser.
try{
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
// URL
url = new URL("url.com");
// URL connection channel.
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("User", "user");
urlConn.setRequestProperty("Password", "password");
urlConn.setRequestProperty("Submit", "Send");
printout = new DataOutputStream(urlConn.getOutputStream());
String content =
"name=" + URLEncoder.encode("Buford Early")
+ "&email=" + URLEncoder.encode("buford@known-space.com");
printout.writeBytes(content);
printout.flush();
printout.close();
input = new DataInputStream(urlConn.getInputStream());
String str;
while (null != ((str = input.readLine()))) {
System.out.println(str);
System.out.println("" + (str + "\n"));
}
input.close();
}
catch(Exception e)
{
}
From what i understand the first parameter in setRequestPropety is the name of the field. the second is what you wish to send.
So the 3rd one i send should submit the data. but im also not sure how i retrieve the data sent back.
the data i receive back is the html code of the webpage i load not the web address of the webpage i want to log into.
any help would be appreciated.