Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.22 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NSURLRequest POST resulting in blank submission
  2. NSError *error = nil;
  3.  NSDictionary *newProject = [NSDictionary dictionaryWithObjectsAndKeys:self.nameField.text, @"name", self.descField.text, @"description", nil];
  4.  NSLog(@"%@", self.descField.text);
  5.  NSData *newData = [NSJSONSerialization dataWithJSONObject:newProject options:kNilOptions error:&error];
  6.  NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
  7.  [url setHTTPBody:newData];
  8.  [url setHTTPMethod:@"POST"];
  9.  NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];
  10.        
  11. NSError *error = nil;
  12. NSString * newProject = [NSString stringWithFormat:@"project[name]=%@&project[description]=%@", self.nameField.text, self.descField.text];
  13. NSData *newData = [newProject dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; // read docs on dataUsingEncoding to make sure you want to allow lossy conversion
  14. NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
  15. [url setHTTPBody:newData];
  16. [url setHTTPMethod:@"POST"];
  17. NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];