网络处理
1 self.data = [NSMutableData data]; 2 3 NSURL *url = [NSURL URLWithString:@"http://192.168.1.106:8080/MJServer/login"]; 4 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 5 6 request.HTTPMethod = @"POST"; 7 8 // 设置请求体 9 NSString *param = @"username=hello&pwd=123&type=XML"; 10 request.HTTPBody = [param dataUsingEncoding:NSUTF8StringEncoding]; 11 12 // 请求头信息可以省略,只要设置了请求体就OK 13 NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self]; 14 [conn start]; 15 16 //当服务器返回数据时调用 17 // 解析服务器返回的数据 18 - (void)connectionDidFinishLoading:(NSURLConnection *)connection { 19 NSString *str = [[[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding] autorelease]; 20 NSLog(@"%@", str); 21 }