Giter Site home page Giter Site logo

afnetworking_jsonmodel's Introduction

HTTP 定义了与服务器交互的不同方法,最常用的有4种,Get、Post、Put、Delete

Put(增),Delete(删),Post(改),Get(查)

GET和POST的区别:

  1. GET请求的数据是放在http包头中的,也就是URL之后
  2. GET提交的数据比较少,最多1024B,速度快
  3. POST的安全性要比GET高,因为GET时,参数数据时明文传输的,容易造成Cross-site request forgery攻击,而POST数据时可以加密的
操作方式 数据位置 明文秘文 数据安全 长度限制 应用场景
GET HTTP包头 明文 不安全 长度较小 查询数据
POST HTTP正文 可明可密 安全 支持较大数据传输 修改数据

AFNetworking

AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];

JSONModel

@protocol resModel
@end
// 这两句要写
@interface resModel : JSONModel
@property (nonatomic, copy) NSString *ghash;
@property (nonatomic, assign) NSInteger gid;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *thumb;
@property (nonatomic, strong) NSArray *questions;

@end

@interface RESModel : JSONModel
@property (nonatomic, assign) NSInteger code;
@property (nonatomic, strong) NSArray* res;
@end

// 定义的属性和后台返回的不一样要mapper,对象可以不一样,例如:resModel

+ (JSONKeyMapper *)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"questionID": @"id",
                                                                  }];
}

afnetworking_jsonmodel's People

Contributors

princesmall avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.