Swift 的 HTTP 开发包:Cycles
jopen
10年前
Cycles 是 Swift 编写的 HTTP 客户端开发包,目前还处于早起开发阶段,只支持 iOS。示例代码:
Cycle.get("https://api.github.com/user/", requestProcessors: [BasicAuthProcessor(username: "user", password: "pass")], responseProcessors: [JSONProcessor()], completionHandler: { (cycle, error) in println("\(cycle.response.statusCode)") // 200 var header = cycle.response.valueForHTTPHeaderField("content-type") println("\(header)") // application/json; charset=utf-8 println("\(cycle.response.textEncoding)") // 4 println("\(cycle.response.text)") // {"login":"user","id":3 ... println("\(cycle.response.object)") // {"avatar_url" = ... })