ios NSURLSession Post请求

- (void)sendPostRequest{

    NSURLSession *session = [NSURLSession sharedSession];

    NSString *urlStr = [NSString stringWithFormat:@"%@AppWebService.asmx/IOS_InsertTrip",urlHead];

    NSURL *url = [NSURL URLWithString:urlStr];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    request.HTTPMethod =@"POST";

 

    NSString *strhttpBody = [NSString stringWithFormat:kInsertTrip,

                                 delegate.SellerCode,

                                 _dataArray[1],

                                 _dataArray[0],

                                 _dataArray[2],

                                 [NSStringstringWithFormat:@"%lf",_longtitede],

                                 [NSStringstringWithFormat:@"%lf",_latitude]

                                 ,_dataArray[4],

                                 mp3str1,

                                 _dataArray[3]];

//        NSLog(@"strhttpBody:%@",strhttpBody);

        request.HTTPBody = [strhttpBody dataUsingEncoding:NSUTF8StringEncoding];

        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError * _Nullable error) {

            NSLog(@"%@",response);

            [self showResponseCode:response];

        }];

        

        [dataTask resume];

 

}

 

/* 输出http响应的状态码 */

 

- (void)showResponseCode:(NSURLResponse *)response {

    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;

    NSInteger responseStatusCode = [httpResponse statusCode];

    if (responseStatusCode ==200) {

      [MyUnitiltycreateMyAlert:selfandTitle:@"提交成功"];

    }else{

       [MyUnitiltycreateMyAlert:nilandTitle:@"提交失败"];

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值