我想发送json数组数据到服务器,但它显示结果失败。 所以plaese纠正我在哪里,我没有wrong.Here是代码我正在使用本:在iOS中发布json数组到服务器?
NSDictionary *[email protected]{@"groupmembersarray":contactsArray};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *post = [NSString stringWithFormat:@"%@",jsonString];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://anaadit.net/caffe/newapp/AddGroupContact.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn==nil) {
NSLog(@"Connection could not be made");
} else {
responseData = [NSMutableData new];
NSLog(@"%@",responseData);
}
和NSURL连接委托方法调用,但响应显示为零。 所以请检查并纠正我。提前感谢。
您的问题已经在这里找到答案:http://stackoverflow.com/questions/7673127/how-to-send-post-or-get-request-containing-json-to-a-url –
我也在使用它,但没有使用,结果是:requestReply:{“result”:“0”} –