External Libraries

Jsoup post form data example

Jsoup post form data example shows how to post form data to a website using Jsoup. Example also shows how to post form data by inspecting the HTML source.

How to post form data using Jsoup?

Jsoup supports HTTP POST method. You can use method method of Connection class to post the form data using Jsoup.

This method sets request method to GET or POST. Default method used by Jsoup is GET.

First of all, you need to determine below given two things to post data using Jsoup.

1) Form action URL, where the data needs to be posted.
2) All request parameters including hidden parameters. For the HTML form it means all the input, select, textarea etc. field’s name and values.

Locate the HTML form which needs to be posted. Let’s take an example HTML form like given below.

Above given form has 5 parameters, out of that 3 inputs are hidden. We need to send all 5 values including hidden to the form action URL “/postpage”. Since action URL is a relative path, we need to make it absolute using base URL of the website we want to post data to.

Once all the parameters have been determined, we can connect to the action URL and send post parameters using data method of Connection class.

This method sets the request parameter. If the method is GET, parameter is sent as query string. If method is POST, parameter is posted in request body.


Instead of using data method for individual post parameters, you can also use data method which accepts a map containing all the post parameter key value pairs.

Please let us know your views in the comments section below.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

  • Tony Sterrett

    How would one get a useful read a useful response from document? just start with jsoup Thanks in Advance. Tony

    • rahimv

      Sorry, I did not get your question. Do you mean how to read webpage and extract data using jsoup?

    • rahimv

      Sorry, I did not get your question. Do you mean how to read webpage and extract data using jsoup?

Join 1000+ fellow learners! Enter your email address below: