简介:当Sb的甲方后台说“整个参数就是一个Json”时,我懵逼了,那AF的字典怎么设置?? 后台你是SB 么? 你可以尝试这样写
NSDictionary *headers = @{ @"content-type": @"application/json",
@"cache-control": @"no-cache",
@"postman-token": @"133b268b-6323-cd8a-05aa-0cf4f211bdf0" };
NSDictionary *parameters = @{ @"address": @"huayanbeili",
// @"cart_id": @25,
@"good_list": @[ @{ @"good_id": @1, @"num": @2 }, @{ @"good_id": @2, @"num": @1 } ],
@"is_buynow": @1,
@"name": @"xieguiyang",
@"phone_number": @"13700000000",
@"remark": @"quick",
@"salesman_id": @1,
@"total_price": @100 };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://codog.com.cn:8080/api/mall/submitOrder"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
return ;
}
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSString * string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"提交订单请求数据 :%@", string);
}];
[dataTask resume];