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?

First, make sure to set proper user agent, referrer and connection timeouts for 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.

Visit Jsoup examples for more. Please let us know your views in the comments section below.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.


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.

Leave a Reply

newest oldest most voted
Tony Sterrett
Tony Sterrett

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


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

Divyansh kumar
Divyansh kumar
hi there, I tried logging in with the code above but always got the html attributes of the error page while logging in. Can you please suggest me a way to find what the error is. I am able to log in with same username and password on the site. ******************************* /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package jsonfetcher; /** * * @author Divyalaptus */ import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.jsoup.Jsoup; import… Read more »