Skip to content

Basic JSoup form Submission

My form submission does not seem to work, I tried JAunt it was able to submit so when using JSoup I don’t understand why it returns 404.

Connection.Response response = Jsoup.connect("")
    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/")
    .data("name", "nameeee")

I tried with:

  • url
  • data "name", "nameeee" produces 404 status
  • data "g7-name", "nameeee" no issue but no submission
  • data "Name", "nameeee" no issue but no submission
  • data with Map<String, String> no issue but no submission


As pointed out by @Pshemo, the code is ok however the data passed is lacking. Those hidden fields contain information required in order for the submission to be valid. In the case of this question the hidden fields are:

<input type="hidden" id="_wpnonce" name="_wpnonce" value="4d18e01372">
<input type="hidden" name="_wp_http_referer" value="/contact/">
<input type="hidden" name="contact-form-id" value="7">
<input type="hidden" name="action" value="grunion-contact-form">
<input type="hidden" name="contact-form-hash" value="07cbf543790375cf26022ad8826a8dbb8787beae">

So aside from the required fields make sure to submit the hidden once as well.

Document document = Jsoup.connect("")
    .data("g7-name", "Super sName")
    .data("_wpnonce", "4d18e01372")
    .data("_wp_http_referer", "/contact/")
    .data("action", "grunion-contact-form")
    .data("contact-form-id", "7")
    .data("contact-form-hash", "07cbf543790375cf26022ad8826a8dbb8787beae")