欢迎加入QQ讨论群258996829

Swift HTTP 网络库 Networking

发布时间:2017-07-07 15:27  回复:0  查看:839  感兴趣:26  赞:0   最后回复:2017-07-07 15:27  
使用简单、功能惊喜,基于 NSURLSession 的网络封装库。功能包括带身份验证请求,支持单元测试(mocking/stubbing),异步执行,图片下载及缓存等实用特性。
GET示例
let networking = Networking(baseURL: "http://httpbin.org")
networking.get("/get") { result in
    switch result {
    case .success(let response):
        let json = response.dictionaryBody
        // Do something with JSON, you can also get arrayBody
    case .failure(let response):
        // Handle error
    }
}
POST示例
let networking = Networking(baseURL: "http://httpbin.org")
networking.post("/post", parameters: ["username" : "jameson", "password" : "secret"]) { result in
    /*
    {
        "json" : {
            "username" : "jameson",
            "password" : "secret"
        },
        "url" : "http://httpbin.org/post",
        "data" : "{"password" : "secret","username" : "jameson"}",
        "headers" : {
            "Accept" : "application/json",
            "Content-Type" : "application/json",
            "Host" : "httpbin.org",
            "Content-Length" : "44",
            "Accept-Language" : "en-us"
        }
    }
    */
}

相关开源代码

您还未登录,请先登录

热门帖子

最新帖子