我正在尝试设置一个非常简单的应用程序,它从输入字段中获取数字,然后使用 NSMutableURLRequest
使用 Google 表单中的操作 URL 将 POSTS 发送到 Google 电子表格.
到目前为止,我有一个简单的文本框和按钮,以及这段代码。我使用的字段名称是:
name="entry.931001663"
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputField;
- (IBAction)submit:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)submit:(id)sender {
NSString *bodyData = self.inputField.text;
NSLog(@"Input = %@", bodyData);
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://docs.google.com/forms/d/1rGpFfI2ebyn_SbuDVVUg7Q4yuvKzd3RRXb0vRxeIDxc/formResponse"]];
[postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[postRequest setHTTPMethod:@"POST"];
[postRequest setHTTPBody:[NSData dataWithBytes:[bodyData UTF8String] length:strlen([bodyData UTF8String])]];
}
@end
最佳答案
我不确定这个错误,但是Google's Sample Code可以帮你。您还可以使用GData Objective C Client使用它。
关于iOS POST 到 Google 表单(电子表格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20281937/