
Untitled
By: a guest on
Aug 1st, 2012 | syntax:
None | size: 1.22 KB | hits: 12 | expires: Never
NSURLRequest POST resulting in blank submission
NSError *error = nil;
NSDictionary *newProject = [NSDictionary dictionaryWithObjectsAndKeys:self.nameField.text, @"name", self.descField.text, @"description", nil];
NSLog(@"%@", self.descField.text);
NSData *newData = [NSJSONSerialization dataWithJSONObject:newProject options:kNilOptions error:&error];
NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
[url setHTTPBody:newData];
[url setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];
NSError *error = nil;
NSString * newProject = [NSString stringWithFormat:@"project[name]=%@&project[description]=%@", self.nameField.text, self.descField.text];
NSData *newData = [newProject dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; // read docs on dataUsingEncoding to make sure you want to allow lossy conversion
NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
[url setHTTPBody:newData];
[url setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];