如何使用C#填写Google表单

时间:2018-09-19 04:41:06

标签: c# .net google-form

该表单已多页,例如this 并且我尝试使用POST请求,但它仅适用于一页形式check this subject。也许还有其他方法?

2 个答案:

答案 0 :(得分:4)

尝试此代码。

WebClient client = new WebClient();
var nameValue = new NameValueCollection();
nameValue.Add("entry.xxx", "VALUE");// You will find these in name (not id) attributes of the input tags 
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("pageHistory", "0,1,2");//Comma separated page indexes
Uri uri = new Uri("https://docs.google.com/forms/d/e/[FORM_ID]/formResponse");
byte[] response = client.UploadValues(uri, "POST", nameValue);
string result = Encoding.UTF8.GetString(response);

我尝试了3页。您可以有任意数量的页面“我猜”。 这将直接提交数据并返回“来自Google表单的成功页面”。

编辑

我还没有使用过“从来没有像现在这样的Google表单”,因此无法找到合适的方法来进行此操作,但这似乎很好。

将其附加到您的uri中以选中多个复选框

?entry.xxxx=Option+1&entry.xxxx=Option2 

entry.xxxx对于一个问题保持不变 如果您有多个问题与复选框,那么它将更改为此

?entry.xxx=Option+1&entry.xxx=Option2&entry.zzz=Option+1&entry.zzz=Option2

值是复选框的标签 用(+)替换(空格)加上(选项1)中的任何类似内容

答案 1 :(得分:0)

Puneet的答案是我找到的关于如何处理具有多个值的复选框的唯一答案。我试图找到一种方法来将多个复选框值放在响应的正文中,而不是放在URL中,但是不能。

本着他的回答的精神,我在C#中制作了一个GoogleFormSubmissionService,以便在C#中轻松处理Google Forms。

您可以在我的要旨中找到它:Google Forms Submission Service in C#