美文网首页
iOS NSURLSession POST 请求

iOS NSURLSession POST 请求

作者: 索性流年 | 来源:发表于2018-05-11 16:12 被阅读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];

相关文章

网友评论

      本文标题:iOS NSURLSession POST 请求

      本文链接:https://www.haomeiwen.com/subject/hlnfdftx.html