JSONWebサービスにデータをPOSTしようとしています。私がこれをすれば私は成功することができます:
curl -d "project[name]=hi&project[description]=yes" http://mypath.com/projects.json
私はそれを達成するためにこのようなコードを使用しようとしています:
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];
私のリクエストは新しいエントリを作成しますが、そのエントリは名前と説明の両方で空白です。上記のコードのNSLogは、適切な出力を生成します。