zoukankan      html  css  js  c++  java
  • 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];

     

     

     

     

  • 相关阅读:
    Sql中使用With创建多张临时表
    sql(join on 和where的执行顺序)
    什么是正则化
    ETL讲解(转)
    MySQL等 SQL语句在线练习
    Sublime text 3 --html
    Sublime text 3 搭建Python3 IDE
    地区列车经过查询
    Lasso回归算法: 坐标轴下降法与最小角回归法小结
    完全卸载VMware
  • 原文地址:https://www.cnblogs.com/LoveStoryJX/p/6889467.html
Copyright © 2011-2022 走看看