HTTP POST到Google表单

编程入门 行业动态 更新时间:2024-10-27 16:26:05
本文介绍了HTTP POST到Google表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要对我的Google表单进行Http POST,并遵循建议( productforums.google/forum/#!topic/docs/iCfNwOliYKY )我创建了这样的URL语法:

I need to do an Http POST to my google form, and following an advice (productforums.google/forum/#!topic/docs/iCfNwOliYKY) I created a URL syntax like this:

docs.google/forms/d/MY_FORM_ID&entry.2087820476=hello&entry.261928712=dear&submit=提交

最终,我将通过iOS和Android进行POST,但我只是在浏览器中对其进行测试,因此无法正常工作.我收到一个Google云端硬盘回复,内容为抱歉,您所请求的文件不存在."该条目不会进入我的回复电子表格.

Eventually I'll do the POST from iOS and Android, but I'm testing it simply in the browser and it doesn't work. I get back a Google Drive response that says "Sorry, the file you have requested does not exist." and the entry doesn't go into my responses spreadsheet.

我想念什么?我到处看,但似乎没有人回答这个问题.

What am I missing? I looked everywhere but nothing seem to answer this question.

我想有时候最好直接在目标平台上进行测试.以下代码适用于iOS:

I guess sometimes it's better to test directly on your target platform. The following code works for iOS:

NSString *post = @"&key1=val1&key2=val2"; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"docs.google/forms/d/MY_FORM_ID/formResponse"]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSHTTPURLResponse* urlResponse = nil; NSError *error = [[NSError alloc] init]; [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

推荐答案

发送POST到以下网址

Send a POST to following url

>: //docs.google/forms/d/e/[FORM_ID]/formResponse?entry.1098499744=AnswerField1&entry.1090138332=AnswerField2

预览表单时,您可以在网址中找到FORM_ID.

You can find your FORM_ID in the url when you preview your form.

要获取字段ID,请检查每个输入标签的名称"属性.或在表单页面的控制台中运行以下脚本.

To get the field ids, check the "name" attribute of each input tag. Or run the following script in the console on the form page.

function loop(e){ if(e.children) for(let i=0;i<e.children.length;i++){ let c = e.children[i], n = c.getAttribute('name'); if(n) console.log(`${c.getAttribute('aria-label')}: ${n}`); loop(e.children[i]); } }; loop(document.body);

应该在控制台中打印类似的内容

Should print something similar to this in your console

Field1: entry.748645480 Field2: entry.919588971

更多推荐

HTTP POST到Google表单

本文发布于:2023-10-12 00:23:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   HTTP   POST   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!