• AFNetworking application/x-www-form-urlencoded 数据请求方式


     

    // 请求数据类实例化

    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];

     

    // 可变request实例化

      NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:str]];

    // 设置 请求方法我POST 

        request.HTTPMethod = @"POST";

     

        // 设置请求头 的 Content-Type格式

        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

        NSString *postStr = [NSString stringWithFormat:@"content=%@",mdic];

        [request setHTTPBody:[postStr dataUsingEncoding:NSUTF8StringEncoding]];

        

       // 请求数据

        NSURLSessionDataTask * dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {

            NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;

            NSInteger responseStatusCode = [httpResponse statusCode];

    //        NSLog(@"---------%@ %ld %@", httpResponse, (long)responseStatusCode ,responseObject);

            if (responseStatusCode == 200) {

                // 成功后的处理

    //            NSLog(@"%@", responseObject);

    //            NSLog(@"返回数据为!!!%@" , responseObject);

                successResponse(responseObject);

            }else {

                // 失败后的处理

                //                                                                  NSLog(@"%@", error);

                if(error.code==-1009){

                    NSDictionary *codeDic=@{@"errCode":@"-1009",@"msg":@"网络未连接!"};

                    successResponse(codeDic);

                }else{

                    NSDictionary *codeDic=@{@"errCode":APPERROR,@"msg":@"未知错误!"};

                    successResponse(codeDic);

                }

            }

        }];

        [dataTask resume];

     

     

     

     

  • 相关阅读:
    申通完美支撑“双11”——亿级包裹背后的云基础设施
    你不知道的云服务器付费新模式,省钱就靠它了
    从“虚拟化”到“新基建”,云计算如何继续乘风破浪?
    Alibaba Cloud Linux 2 LTS 快速启动优化实践
    Alibaba Cloud Linux 2 LTS 正式发布,提供更高性能和更多保障!
    连续四年,神龙又扛住了“双11”
    飞天丨想象没有边界,创造改变未来
    清华大学高琪瑞:基于云端视觉计算建设全球先进的工科实验教学平台
    映客高级技术总监黄继:7天从开发到上线,云上高效运维实践与探索
    三维家如何借助云变革家居行业
  • 原文地址:https://www.cnblogs.com/LoveStoryJX/p/6889467.html
Copyright © 2020-2023  润新知