NSURL *url=[NSURL URLWithString:GetInstalment];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
//此处发送一定要设置,这个地方把字典封装为json格式
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSNumber *numbs = [NSNumber numberWithLong:[self.timeChuo integerValue]];
NSDictionary *postDics = @{@"app_id":[NSString stringWithFormat:@"%@", BC_app_ID],
@"timestamp":numbs,
@"app_sign":[NSString stringWithFormat:@"%@", self.AppSign],
@"phone":[NSString stringWithFormat:@"%@", self.telNum.text]};
NSData *data = [NSJSONSerialization dataWithJSONObject:postDics options:NSJSONWritingPrettyPrinted error:nil];
request.HTTPBody = data;
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"%@ %@", response, data);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
if (dict[@"error"]) {
NSLog(@"sss%@",dict[@"error"]);
}
else
{
NSLog(@"%@", dict);
NSLog(@"qqq%@",dict[@"success"]);
}
}];
[dataTask resume];
}