我需要对我的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表单
发布评论