测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可 | Apache 2 |
发布最新发布 | 2017 年 9 月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由corinne krych,Julio Cesar,Daniel Passos,Massimiliano Ziccardi维护。
该模块目前使用 Xcode 8 构建,并支持 iOS8、iOS9、iOS10。
一个薄层,负责处理你的 HTTP 请求,与 NSURLSession 一起工作。负责
100% Swift 3.0。
项目信息 | |
---|---|
许可 | Apache 许可证,版本 2.0 |
构建 | CocoaPods |
文档 | http://aerogear.org/ios/ |
问题跟踪器 | https://issues.jboss.org/browse/AGIOS |
邮件列表 | aerogear-users (订阅) |
aerogear-dev (订阅) |
要执行 HTTP 请求,请使用 Http 对象中方便的方法。以下是一个使用示例
let http = Http(baseURL: "http://server.com")
http.request(.get, path: "/get", completionHandler: {(response, error) in
// handle response
})
http.request(.post, path: "/post", parameters: ["key": "value"],
completionHandler: {(response, error) in
// handle response
})
...
库还利用了内置的构建基础支持 http/digest 认证,并通过允许在请求上传递凭据对象来公开一个方便的接口。以下是一个示例
注意:建议在执行此类身份验证时使用 HTTPS
let credential = URLCredential(user: "john",
password: "pass",
persistence: .none)
http.request(.get, path: "/protected/endpoint", credential: credential,
completionHandler: {(response, error) in
// handle response
})
您还可以按保护空间设置每个凭据,一旦服务器请求 http 挑战,就自动获取它,因此不必在每个请求上传递凭据。在这种情况下,您必须用自定义会话配置对象初始化 Http
对象,该对象的凭据存储已用您的凭据初始化。
// create a protection space
let protectionSpace = URLProtectionSpace(host: "httpbin.org",
port: 443,
protocol: NSURLProtectionSpaceHTTP,
realm: "[email protected]",
authenticationMethod: NSURLAuthenticationMethodHTTPDigest)
// setup credential
// notice that we use '.ForSession' type otherwise credential storage will discard and
// won't save it when doing 'credentialStorage.setDefaultCredential' later on
let credential = URLCredential(user: "user",
password: "password",
persistence: .forSession)
// assign it to credential storage
let credentialStorage = URLCredentialStorage.shared
credentialStorage.setDefaultCredential(credential, for: protectionSpace);
// set up default configuration and assign credential storage
let configuration = URLSessionConfiguration.default
configuration.urlCredentialStorage = credentialStorage
// assign custom configuration to Http
let http = Http(baseURL: "http://httpbin.org", sessionConfig: configuration)
http.request(.get, path: "/protected/endpoint", completionHandler: {(response, error) in
// handle response
})
为了支持OAuth2协议,我们创建了一个独立的库aerogear-ios-oauth2,它易于集成,以便为与OAuth2受保护端点的通信提供即装即用的支持。请参阅我们文档页面上的“Http和OAuth2模块”部分以获取更多信息。
您想在自己的终端尝试吗?请按照以下步骤操作。
克隆此项目
获取依赖项
该项目使用OHHTTPStubs框架来模拟其HTTP网络请求,并利用CocoaPods释放来处理其依赖项。作为先决条件,请安装CocoaPods,然后安装pods。在项目根目录中运行
pod install
要将库添加到您的项目中,您可以使用CocoaPods或在项目中手动安装。请参阅以下各节中的说明。
有关当前版本的更多详细信息,请参阅我们的文档。
如果您想帮助开发AeroGear,您可以通过开发人员邮件列表加入我们,加入Freenode上的#aerogear,或者在Twitter @aerogears上发消息给我们。
还要花些时间浏览贡献者指南
加入我们的用户邮件列表以提问或获得帮助!我们真心希望您喜欢使用AeroGear进行应用开发!
如果您发现了一个错误,请创建一个Jira票据,并包含重现它的步骤。