Justhttp 介绍
Just 是一款用 Swift 语言编写的,受 python-requests 影响的轻量级 HTTP 客户端库。
Just 可以让你毫不费力地完成如下工作:
-
URL 查询
-
定制报文(headers)
-
构建 JSON HTTP body
-
重定向控制
-
多文件上传
-
Basic/Digest 认证
-
Cookies
-
同步/异步请求
-
用户友好的调用结果
用法:
使用 Just 发起一个请求的例子:
// talk to registration end point let r = Just.post( "http://justiceleauge.org/member/register", data: ["username": "barryallen", "password":"ReverseF1ashSucks"], files: ["profile_photo": .URL(fileURLWithPath:"flash.jpeg", nil)] ) if (r.ok) { /* success! */ }
下面是使用异步方法完成上面工作的例子:
// talk to registration end point Just.post( "http://justiceleauge.org/member/register", data: ["username": "barryallen", "password":"ReverseF1ashSucks"], files: ["profile_photo": .URL(fileURLWithPath:"flash.jpeg", nil)] ) { (r) if (r.ok) { /* success! */ } }
你可以在这个
Playground
中了解更多 Just 库的使用方法。
安装:
-
源代码文件:只须将唯一的一个源文件拖入 playground 或者直接拖入到你的代码中
-
Git 子模块:将改 repo 作为 Git 子模块添加到你的 git 项目中,然后拖动 Just.xcodeproj 到你的 Xcode 项目中以便你可以创建一个对 Just.framework 的依赖并且进行链接
-
动态框架:因为 Just 是一个针对 OS X 和 iOS 的动态框架,所以 Carthage 就可以安装它。
Justhttp 官网
https://github.com/justhttp/Just
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。