FORM Authorization with POST

T

Tim Frangioso

Hi All,

I know this subject has been discussed on this newsgroup. I have researched
previous answers and I am bewildered.

I am trying to log into
"http://unabridged.merriam-webster.com/noauth/login.php" so I can access the
dictionary definitions programmatically.

The form looks like this:

<form name=access method=post
action="http://unabridged.merriam-webster.com/noauth/login.php">
User Name: <input type=text name=usermail size=30 maxlength=80 value=""><br>
Password: <input type=password name=userpass size=20 maxlength=20>
<div align=right>
<input type=checkbox name=savepass value=checked checked> save log-in
information
<input type=hidden name=nocookies value="">
<input type=hidden name=enterkey value="hit">
<input type="submit" name=userlogin value="Log in"> </div>
</form>


Here is the code that I am using:

************************Begin Code**********************************
String usermail = "usermail="+URLEncoder.encode("(e-mail address removed)",
"UTF-8");
String userpass = "userpass="+URLEncoder.encode("tfrangio", "UTF-8");

URL location = new
URL("http://unabridged.merriam-webster.com/noauth/login.php");
HttpURLConnection currentUrlCon =
(HttpURLConnection)location.openConnection();
currentUrlCon.setAllowUserInteraction(true);
currentUrlCon.setRequestMethod("POST");
String body = usermail + "&" + userpass;
currentUrlCon.setRequestProperty( "Content-Length", ""+body.length());
currentUrlCon.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
currentUrlCon.setDoOutput(true);
//write the request
PrintWriter pw = new PrintWriter(currentUrlCon.getOutputStream());
pw.write(body);
pw.flush();
pw.close();
//Printout response
BufferedReader currentMsg = new BufferedReader(new
InputStreamReader(currentUrlCon.getInputStream()));
completeLine = "";
while ( (inputLine = currentMsg.readLine()) != null) {
completeLine += inputLine; }
System.out.println("HTML returned=\n"+completeLine);
//short verification of 1st POST
System.out.println("response="+currentUrlCon.getResponseCode()+"/"+currentUr
lCon.getResponseMessage());

********************************End Code******************************

I have tried listing out all the other parameters and values for the form
but, none of them worked.

For example I passed in the following for the value for the body string:
"usermail=tfrangio%40acm.org&userpass=tfrangio&enterkey=hit&userlogin=Log+in
"

I have also tried this:
"usermail=tfrangio%40acm.org&userpass=tfrangio&savepass=checked&nocookies=&e
nterkey=hit&userlogin=Log+in"

Thinking that maybe the handling code dies on the server side when it can
not find the correct value for a parameter.

Any other ideas on what I doing wrong?

Thanks,
-Tim
 
A

ak

What you do is work only with GET messages.
POST messages must have multipart format (like email).
I implemented this 3 years ago (for uploading). If you want see my code
contact me - info at imagero dot com.

But first look at javax.mail package.

Regards

Andrei
 
T

Tim Frangioso

Ak,

What do you mean three part message? Can you post an example here so I
can see what you are talking about?

Thanks,
-Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top