【发布时间】:2015-10-09 21:56:46
【问题描述】:
我只是在玩 Alamofire 框架并进行一些 api 调用。但是我观察到 alamofire 中有两种请求方法:
public func request(method: Method, URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = .URL, headers: [String: String]? = nil) -> Request{...}
和
public func request(URLRequest: URLRequestConvertible) -> Request {...}
我觉得这很有趣,因为第一个方法原型很详细而且很容易理解。但是第二个很混乱,我知道它需要一个符合 Alamofire 定义的 URLRequestConvertible 协议的参数。
在第二个请求原型中,从未指定需要使用的 HTTP 方法(GET 或 POST),那么 alamofire 是如何知道要使用哪种 HTTP 方法的。有没有办法让 alamofire 在发出请求时知道使用哪种 http 方法。
另外,这两种方法(如果有的话)还有哪些其他显着差异?首选哪一种?为什么?
谢谢。
【问题讨论】: