• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Peculiar HTML Form INPUT Tag

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to automate a form POST operation for a secure logon page. One of the form input tags looks like this:

<input type="hidden" name="a_name" value=""/>

The tag is all in lower case as shown. (Other INPUT tags in the same form are in upper case, but I didn't think that mattered.) The "/" following the empty string at the end of the tag is shown in red when the page source is viewed in Mozilla Firefox. When I use URLEncoder.encode("","UTF-8") to represent the empty string value in the POST string, nothing is inserted.

The POST operation otherwise transmits fine and returns a response fine, but the response indicates that the field values are incorrect and the logon is unsuccessful. I don't think I am properly representing the ""/ value in the POST string, and I think the red slash is a clue. Does anyone have any ideas or suggestions?

More generally, what is the proper way to represent an empty string value in a POST string?

Many thanks.

Bill Denniston
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The slash indicates the closing tag of the INPUT element; its presence or absence has no bearing on the semantics of the element.

How are you sending the POST request - using the HttpUrlConnection class, the HttpClient library or some other means? Here's an example of using the former.
[ December 05, 2008: Message edited by: Ulf Dittmer ]
 
Bill Denniston
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I now think there may be a cookie being sent with (an assumed) previous page load that I am not sending back in this post. (If so, I'm not sure how to find the cookie nor how to send it back with the POST; suggestions or examples appreciated.)

Here's my code. (I have neutralized the login username and password values, but the code otherwise runs fine as previously mentioned.)

import java.io.*;
import java.net.*;

public class URLTest {
public static void main(String[] args) throws Exception {

URL url = new URL("https://www.aopa.org/login/index.cfm?method=validate&WT.svl=LogBoxLogin");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches (false);
connection.setInstanceFollowRedirects(false);

String request = "username=" + URLEncoder.encode ("99999","UTF-8") +
"&password=" + URLEncoder.encode ("******","UTF-8") +
"&source=" + URLEncoder.encode ("secondary","UTF-8") +
"&requestUri=" + URLEncoder.encode ("/index.html","UTF-8");

OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write(request);
out.close();

BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));

String response;

while ((response = in.readLine()) != null) {
System.out.println(response);
}
in.close();
}
}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there are cookies involved -and especially if there's a back-and-forth of several requests and responses- then I'd advise to use the HttpClient library. It supports cookies between requests (which I think the HttpURLConnection class doesn't).

user docs

example code
[ December 05, 2008: Message edited by: Ulf Dittmer ]
 
See where your hand is? Not there. It's next to this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic