Post from Java to a Google docs form
CodeDevTutorials
A working example : sending a request to a Google doc form with okhttp.
You have to find the name of your inputs by looking at the source code of the form, the name starts with entry. following by a number:
<input name="entry.361168075" value="" class="ss-q-short" id="entry_361168075" dir="auto" aria-label="What's your favorite color " aria-required="true" required="" title="" type="text">
Write a small program:
import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class Test { public static void main( String[] args ) { try { OkHttpClient client = new OkHttpClient(); FormBody body = new FormBody.Builder() .add( "entry.361168075", "Red" ) .build(); Request request = new Request.Builder() .url( "https://docs.google.com/forms/d/1k96sccTC_24b6jo9Fs4h_ML-FVKHCMElgjUzOwSkwu4/formResponse" ) .post( body ) .build(); Response response = client.newCall( request ).execute(); System.out.println( response.isSuccessful() ); } catch ( Exception e ) { e.printStackTrace(); } } }
And see the result in the spreadsheet output:
🙂
Leave a comment