#pragma mark - - 发送数据
// 发送数据
- (void)sendData:(NSDictionary *)dic {
// 1.创建请求
// www.ZXWQWZ.com 域名
NSString *zxwqwz = @"UploadFreeManual";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", BASE_URL, zxwqwz]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
// 2.设置请求头
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// 3.设置请求体
NSDictionary *json = dic;
/*
NSDictionary *json = @{
@"order_id" : @"123",
@"user_id" : @"789",
@"shop" : @"Toll"
};*/
// NSData --> NSDictionary
// NSDictionary --> NSData
NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
request.HTTPBody = data;
// 4.发送请求
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@" 服务器返回的数据: %@", data);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSLog(@" ======= %@", dict);
NSString *success = dict[@"retcode"];
if ([success isEqualToString:@"2000"]) {
NSString *str = dict[@"msg"];
NSLog(@" 成功: %@", str);
}else {
NSLog(@" 问题来了 ");
// 所有的错误信息 都进来 把本次的录制保存一份 存储
}
}];
}