如何用C#填写Google表单

Ask*_*ich 3 .net c# google-forms

该表单是多页的,就像 这样 ,我尝试使用 POST 请求,但它仅适用于单页表单,请检查此主题。也许还有其他方法?

Pun*_*dal 5

试试这个代码。

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);
Run Code Online (Sandbox Code Playgroud)

我尝试了 3 页。“我猜”你可以拥有任意数量的页面。这将直接提交数据并返回“Success page from google forms”。

编辑

我从来没有“像以前一样”使用过谷歌表单,所以无法找到合适的方法来做到这一点(如果有的话),但这似乎工作得很好。

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

?entry.xxxx=Option+1&entry.xxxx=Option2 
Run Code Online (Sandbox Code Playgroud)

对于一个问题,entry.xxxx 保持不变,如果您有多个带有复选框的问题,那么它会更改为这样

?entry.xxx=Option+1&entry.xxx=Option2&entry.zzz=Option+1&entry.zzz=Option2
Run Code Online (Sandbox Code Playgroud)

value 是复选框的标签,将(空格)替换为(+)加上(如果有)类似(选项 1)