如何用C#填写Google表单

问题描述 投票:3回答:2

表单是多重的,就像this一样,我尝试使用POST请求,但它只适用于单页表单,check this subject。也许还有另外一种方法?

c# .net google-form
2个回答
3
投票

试试这个代码。

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页。你可以有任意数量的页面“我猜”。这将直接提交数据并返回“谷歌表单的成功页面”。

编辑

我没有使用过谷歌表格“永远不会”,所以如果有的话,无法找到合适的方法,但这似乎工作得很好。

将此附加到您的uri以获取多个复选框

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

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

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

value是复选框的标签替换(空格)与(+)加上(如果有的话)(选项1)


0
投票

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

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

你可以在我的要点上找到它:Google Forms Submission Service in C#

© www.soinside.com 2019 - 2024. All rights reserved.