I am trying to log into a reports system using java. So far, I have tried MANY different implementations that have used HttpURLConnection. The HTML I am trying to post to boils down to:
<form name="logonForm" method="POST" action="http://remoteserver/logon.object">
<input type="hidden" name="qryStr" value="">
<input type="hidden" name="cmsVisible" value="true">
<input type="hidden" name="authenticationVisible" value="true">
<input type="hidden" name="referer" value="">
<input type="hidden" name="refererFormData" value="">
<input type="hidden" name="isFromLogonPage" value="true">
<input type="text" name="cms" value="xxxxx" class="textfield" id="apsTextEdit">
<input type="text" name="username" value="xxxxx"class="textfield" id="usernameTextEdit">
<input type="text" name="password" value="xxxxx"class="textfield" id="passwordTextEdit">
<select name="authType"id="authenticationSelectBox">
<option selected value='xxxxx'>xxxxx</select>
<input type="submit" name="SUBMIT">
</form>
I know this form provides valid input, because when I click submit in a browser, it logs me into my reports system. However, I always get the above html back as a response when I send a programmatic request. Note I have tried about a million implementations that have used HttpURLRequest. One example:
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(parameters);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
String allLines = "";
while ((line = rd.readLine()) != null) {
allLines += "\n" + line; // Process line...
}
wr.close();
rd.close();
return allLines;
Where 'parameters' ranges from nothing to every URL-encoded parameter from the HTML I posted, and connection is (currently, as in I've tried other configurations) set up like:
connection = (HttpURLConnection) url.openConnection();
HttpURLConnection.setFollowRedirects(true);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=" + "UTF-8");
connection.setUseCaches(false);
connection.connect();
I know the details are a little sparse, so let me know if you need any more info and thanks very much for any input!