我需要对我的Google表单进行Http POST请求,并且根据建议(http://productforums.google.com/forum/#!topic/docs/iCfNwOliYKY)创建了以下URL语法:
https://docs.google.com/forms/d/MY_FORM_ID&entry.2087820476=hello&entry.261928712=dear&submit=Submit
最终我将要在iOS和Android上执行POST,但我现在仅在浏览器中测试它并且它无法工作。我收到了一个Google Drive响应:"抱歉,您请求的文件不存在。" 并且该条目未进入我的响应电子表格。
我错过了什么?我已经到处找过了,但没有找到答案。
编辑:
我想有时直接在目标平台上进行测试可能更好。以下代码适用于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:@"https://docs.google.com/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];