Submit data to a google form in a programmatical way – unsecured form

Nowadays google forms are the most convenient way of collecting information and when it comes to google forms, usually the recommended way is to have security enabled so the user needs to be logged in before submitting the form. But sometimes when we are conducting surveys that are not possible as we need to share the form with everyone.

Even though the blog is about submitting data to a google form, the same logic can be applied to other forms as well.

Here I have chosen Java as the programming language but the same can be done with other programming languages as well.

Understanding the problem

When we are submitting a google form what actually happens behind the scene is, the browser sends a post request to google servers with all the filled values as variables. You can analyze this by following the below steps

  1. Create a sample google form.
  2. Open developer tools before submitting the form and go to the Network tab.
  3. Submit the google form.
  4. Note that all values will be there under ‘Form Data’. Names of the fields will be wrapped by some random string and those will be something like “entry.2089670836

Now the only thing we need to do is send a post request to that URL with all the required data.

Implement the solution using JAVA

After doing the above steps you can find the URL and it will be something like the following. FORM_ID should be replaced by your form id which can be identified by going through the URL of the google form<FORM_ID>/formResponse

Now when we are passing the values programmatically, the following headers should be set. The values for these headers can be extracted by analyzing the Analytics Tab as mentioned above.

  • Accept
  • Host
  • User-Agent
  • Accept-Encoding
  • Accept-Language
  • DNT
  • Referer
  • Cookie
  • Connection
  • Content-Type

For this implementation, I have used a third party library called jersey-client to make the network call. After adding this dependency my pom file looks like below

After adding the above dependency, the following code has been used to make the actual POST request. Please note that the FORM_ID and the ‘metaData’ have to be replaced accordingly. Here the metaData is the values that you want to pass and that will be something like below


Also don’t forget to replace the values for each header accordingly.

Please try this and comment your thoughts bellow. ❤️ 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.