Skip to content

Instantly share code, notes, and snippets.

@TomLiu
Created August 25, 2011 07:20
Show Gist options
  • Save TomLiu/1170154 to your computer and use it in GitHub Desktop.
Save TomLiu/1170154 to your computer and use it in GitHub Desktop.
cocoa send request to Google Doc
NSString *postwords = @"test";
NSString *post = [NSString stringWithFormat:@"entry.0.single=%@&pageNumber=0&backupCache=&submit=Submit",postwords];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [post length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"https://docs.google.com/spreadsheet/formResponse?formkey=yourformkey;ifq"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[NSURLConnection connectionWithRequest:request delegate:self];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment