【发布时间】:2015-09-05 02:40:06
【问题描述】:
我正在寻找很多示例,主要来自网络上的@matt,但我无法获得这项工作:
import Alamofire
extension Request {
public func debugLog() -> Self {
debugPrint(self)
return self
}
}
func login(userName: String, passWord: String) -> String {
let manager = Manager.sharedInstance
// Specifying the Headers we need
manager.session.configuration.HTTPAdditionalHeaders = [
"Content-Type": "application/json",
"User-Agent": "test",
"Cache-Control": "no-cache",
"Authorization": "apikey"
]
// When
let params =
["userName" : userName,
"passWord" : passWord]
Alamofire.request(.POST, Constants.apiURL.url + "users/login", parameters: params)
.validate()
.debugLog()
.responseJSON { responseRequest, responseResponse, responseResult in
NSLog(String(responseRequest)) // never enter here
NSLog(String(responseResponse))
NSLog(String(responseResult))
}
return ""
}
它永远不会进入我的块 .responseJSON。无论我使用什么作为参数、强制错误或从调试中获得完美的 cURL 命令,它都无法正常工作。
我的 cURL 很好,我可以在 bash 中正常执行它,我得到了一个很好的 json 结果。
curl -i \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Cache-Control: no-cache" \
-H "User-Agent: test" \
-H "Authorization: apikey" \
-H "Content-Type: application/json" \
-d "passWord=123&userName=123" \
"http://api.cc/users/login"
【问题讨论】:
-
试图将 ``responseJSON ` 更改为
responseString -
嗨,有同样的行为。谢谢。
-
哪个版本的 Alamofire(如果可以的话)和哪个版本的 Xcode?span>
-
pod 'Alamofire', :git => 'github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'