I want to submit data from Java to a Google form. Using JSoup and the following code I can't achieve this goal. I've tried several different methods and I've searched for few days with still no result. My last resort is to bug some intelligent people on Stackoverflow. Can anybody help me?
String url = "http://docs.google.com/forms/d/1OEBmIXG-enn3Yb48JKfRHjHFsTnGUZkIR_7KHR_raF0/viewform";
try {
Jsoup.connect(url)
.data("entry.1278622432", "reply")
.data("entry.1578309861", "reply")
//.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.userAgent("Mozilla")
.post();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Error:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=405, URL=http://doc
Html error code:
10.4.6 405 Method Not Allowed
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
(Solution doesn't have to be with JSoup.)
You are doing a post on the view form URL. When submitting this form from the browser, what it does is:
curl \
'https://docs.google.com/forms/d/1OEBmIXG-enn3Yb48JKfRHjHFsTnGUZkIR_7KHR_raF0/formResponse' \
-H 'Host: docs.google.com' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: nl,en-us;q=0.7,en;q=0.3' -H 'Accept-Encoding: gzip, deflate' -H 'DNT: 1' \
-H 'Referer: https://docs.google.com/forms/d/1OEBmIXG-enn3Yb48JKfRHjHFsTnGUZkIR_7KHR_raF0/viewform' \
-H 'Cookie: GDS_PREF=hl=en_US; __utma=184632636.34...1517515.2; PREF=ID=4922e3....:FF=0:LD=nl:TM=1380883655:LM=1381731571:S=JvyU_OhlkQ7rE3x3; NID=67=hy29...sglz4PVeS53BZ4eLkYK_wDm9-jmdj7apqNZv6rEwUPDobxjagtLN5gpl4A7v0oA' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'entry.1278622432=&entry.1578309861=&draftResponse=%5B%5D%0D%0A&pageHistory=0&fbzx=-5804634750901421753'
(thanks FireBug!) so that's what you'll have to emulate. Starting with the post to .../formResponse