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


     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 }
  • 相关阅读:
    CentOS7安装MySQL5.7
    python基础 元组操作
    初识Python Python的历史(转)
    Python基础 基本数据类型
    createEvent 流沙
    GetLogicalDriveStringS获取驱动器根路径 流沙
    监控文件系统用得到的API 流沙
    Windows I/O 操作CreateFile 流沙
    脚本加入域 流沙
    WMI事件 流沙
  • 原文地址:https://www.cnblogs.com/seeworld/p/6006308.html
Copyright © 2020-2023  润新知