【发布时间】:2017-01-11 00:52:08
【问题描述】:
我正在尝试使用 Alamofire 4 和 swift 3 编写 REST 客户端的基本示例,但无论我尝试访问什么服务,响应总是为零。
我是否缺少任何配置?
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request("https://httpbin.org/get").responseJSON { response in
print(response.request) // original URL request
print(response.response) // HTTP URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
播客文件
platform :ios, '9.0'
target 'RESTClient' do
use_frameworks!
# Pods for RESTClient
pod 'Alamofire', '~> 4.2'
pod 'SwiftyJSON'
end
Info.plist
【问题讨论】:
-
我觉得有必要在构造函数中包含请求方法类型
-
在 Alamofire 4 中没有必要。我复制的这段代码与github.com/Alamofire/Alamofire 完全相同