码迷,mamicode.com
首页 > 其他好文 > 详细

如果向服务器发送多值参数

时间:2016-10-28 03:47:32      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:using   服务器   operation   reading   erro   style   body   request   gen   

 1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 2 {
 3     // 1.URL
 4     NSURL *url = [NSURL URLWithString:@"http://localhost:8080/MJServer/weather"];
 5     
 6     // 2.请求
 7     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
 8     
 9     // 3.请求方法
10     request.HTTPMethod = @"POST";
11     
12     // 4.设置请求体(请求参数)
13     NSMutableString *param = [NSMutableString string];
14     [param appendString:@"place=beijing"];
15     [param appendString:@"&place=tianjin"];
16     [param appendString:@"&place=meizhou"];
17     request.HTTPBody = [param dataUsingEncoding:NSUTF8StringEncoding];
18     
19     // 5.发送请求
20     [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
21         if (data == nil || connectionError) return;
22         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
23         NSString *error = dict[@"error"];
24         if (error) {
25             [MBProgressHUD showError:error];
26         } else {
27 //            NSArray *weathers = dict[@"weathers"];
28             NSLog(@"%@", dict);
29         }
30     }];
31 }

 

如果向服务器发送多值参数

标签:using   服务器   operation   reading   erro   style   body   request   gen   

原文地址:http://www.cnblogs.com/seeworld/p/6006308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!