Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
- 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/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];
- NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
- post =[post stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
- NSURL *url =[NSURL URLWithString:@"https://docs.google.com/forms/d/FORM_ID/formResponse"];
- ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
- [request addPostValue:self.firstName.text forKey:@"entry.xxxx"];
- [request addPostValue:self.phone.text forKey:@"entry.yyyy"];
- [request addPostValue:self.email.text forKey:@"entry.zzzz"];
- [request startAsynchronous];
- NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
- NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
- NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
- NSString *encodeUrl = [@"document/d/Hphb4NsfxZLxTl7p3LMCWCpm9MCWskgoTFWzhP1Fpqap/edit" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- //setup the post using AFHTTPClient
- AFHTTPClient *afHttpRequest = [[[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://docs.google.com"]] autorelease];
- NSURLRequest *request = [afHttpRequest requestWithMethod:@"POST" path:encodeUrl parameters:post];
- //loading indicator
- [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
- [[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
- [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
- AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
- success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
- //some response
- }
- failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
- //the request fails
- }
- ];
- //fire the request
- [operation start];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement