![](/img/trans.png)
[英]taskWillPerformHTTPRedirection never called in Alamofire 5
[英]Alamofire called twice
我正在嘗試使用Alamofire,但它真的很奇怪。 我正在調用這個函數和調試,它被調用兩次,我不知道為什么。
在第一次它只是跳過所有功能而沒有做任何事情,第二次正常運行。
override func viewDidLoad() {
super.viewDidLoad()
download{
//do stuffs
}
}
func download(completed: @escaping DownloadComplete){
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)")
}
completed()
}
}
這個ViewController由PerformSegue WithIdentifier調用。 我不知道會是什么。
它可能是調試語句本身導致額外的請求。 例如,如果您執行此類操作以查看請求的外觀,那么它實際上會發出請求
let test = session.request(url);
print("Debug print request")
// this will make first call even though response is not handled
debugPrint(test)
// second call
session.request(url).responseJson....
我假設你在請求行上設置了一個斷點。 當你這樣做時,它會觸發兩次。 第一次發出請求時,第二次收到回復。 編譯器將完成塊視為1行並再次在同一行上觸發。
如果沒有重復的舊連接,請檢查故事板(連接檢查器,⌘+⌥+ 6)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.