Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
  2. NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
  3. NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
  4.  
  5. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  6. [request setURL:[NSURL URLWithString:@"https://docs.google.com/forms/d/FORM_ID/formResponse"]];
  7. [request setHTTPMethod:@"POST"];
  8. [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  9. [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  10. [request setHTTPBody:postData];
  11.  
  12. NSHTTPURLResponse* urlResponse = nil;
  13. NSError *error = [[NSError alloc] init];
  14. [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  15.  
  16. NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
  17. post =[post stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  18. NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  19.  
  20. NSURL *url =[NSURL URLWithString:@"https://docs.google.com/forms/d/FORM_ID/formResponse"];
  21. ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
  22.  
  23. [request addPostValue:self.firstName.text forKey:@"entry.xxxx"];
  24. [request addPostValue:self.phone.text forKey:@"entry.yyyy"];
  25. [request addPostValue:self.email.text forKey:@"entry.zzzz"];
  26.  
  27. [request startAsynchronous];
  28.  
  29. NSString *post = [Util append:@"&entry.xxxxx=", self.firstName.text, @"&entry.yyyyyyy=", self.phone.text, @"&entry.zzzzzzzz=", self.email.text, nil];
  30. NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  31. NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
  32.  
  33. NSString *encodeUrl = [@"document/d/Hphb4NsfxZLxTl7p3LMCWCpm9MCWskgoTFWzhP1Fpqap/edit" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
  34.  
  35. //setup the post using AFHTTPClient
  36. AFHTTPClient *afHttpRequest = [[[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://docs.google.com"]] autorelease];
  37. NSURLRequest *request = [afHttpRequest requestWithMethod:@"POST" path:encodeUrl parameters:post];
  38.  
  39. //loading indicator
  40. [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
  41. [[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
  42.  
  43. [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
  44. AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
  45. success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
  46. //some response
  47. }
  48. failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
  49. //the request fails
  50. }
  51. ];
  52. //fire the request
  53. [operation start];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement