iOS NSURLSession POST 请求

2018-05-11  本文已影响0人  索性流年
NSURL *storeURL = [NSURL URLWithString:@"http://10.191.188.16:9856/pay/Iospay"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:storeURL];

request.HTTPMethod = @"POST";

request.HTTPBody =  [[NSString stringWithFormat:@"receipt=%@&type=JSON",receiptStr] dataUsingEncoding:NSUTF8StringEncoding];

request.timeoutInterval = 60;

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
    if (data) {
        //JSON解析
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        
        //                NSLog(@"==== %@ ====",dic);
        
    }else{
        //                NSLog(@"==== 获取数据失败 ====");
    }
}];

[dataTask resume];
上一篇 下一篇

猜你喜欢

热点阅读