【发布时间】:2014-08-03 00:09:40
【问题描述】:
我不知道如何通过 POST 使用 NSURLSession 将字典中的值传递到服务器。请帮我解决这个问题。
我的字典包含联系信息(仅限姓名和电话号码),其中键是人名,值是他们的电话号码。
我有使用 nsurl 连接的示例代码 - 如何将其转换为使用 NSURLSession?
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://holla.com/login"]];
request.HTTPMethod = @"POST"; [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"212333333",@"ABCD",@"6544345345",@"NMHG", nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
request.HTTPBody = jsonData;
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
【问题讨论】:
标签: ios nsurlsession