You need to know the name of the input elements (including the submit button!). They should be sent as request parameters along with the desired value. You need to compose an HTTP request string based on these name-value pairs and write it to the request body.
Suppose the generated ASPX HTML is as follows:
<form action="page.aspx" method="post"> <input type="text" name="foo" /> <input type="radio" name="bar" value="option1" /> <input type="radio" name="bar" value="option2" /> <input type="radio" name="bar" value="option3" /> <input type="submit" name="action" value="send" /> </form>
If you want to actually enter hello as the input value, select the second option option2 and press the submit button, then the final query line should look like this:
foo=hello&bar=option2&action=send
Write this in the request body. In the case of URLConnection this will be:
String query = "foo=hello&bar=option2&action=send"; String charset = "UTF-8"; URLConnection connection = new URL("http://example.com/page.aspx").openConnection(); connection.setDoOutput(true); // Triggers POST method. connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); connection.getOutputStream().write(query.getBytes(charset));
See also:
Balusc
source share