我找了很多的例子,主要是從網絡上的任何@馬特的結果,但我不能得到這個工作:Alamofire不能得到斯威夫特2
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' – Bannings
嗨,具有相同的行爲。謝謝。 – GIJOW
Alamofire的哪個版本(如果可以的話)以及哪個版本的Xcode? – cnoon