我正在尝试使用Google表单中的操作网址设置一个非常简单的应用程序,该应用程序从输入字段中获取一个数字,然后使用NSMutableURLRequest
将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