ios NSURLSession Post请求

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012485897/article/details/55252471

- (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:@"提交失败"];

    }

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页