如何用 C# 填写 Google 表格

How to fill Google form with C#

表格是多页,喜欢this 我尝试使用 POST 请求,但它仅适用于单页表单 。也许还有其他方法?

试试这个代码。

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 页。您可以拥有任意数量的页面 "i guess"。 这样会直接提交数据,return "Success page from google forms".

编辑

我没有使用过 google 表单 "like never",所以无法找到合适的方法来执行此操作(如果有的话),但这似乎工作得很好。

将此附加到您的多个复选框的 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 是您的复选框的标签 将 (whitespace) 替换为 (+) plus if any like in (Option 1)

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

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

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