在游乐场使用Alamofire延迟发出http请求

时间:2015-11-05 03:05:15

标签: xcode swift alamofire swift-playground

我遇到一个奇怪的问题,我操场上的Alamofire.request(.GET)声明在操场上拖延后被执行

设置:我按照以下link导入Alamofire框架,以测试xcode playground中的网络请求。

这是我在操场上的代码。当我查看我的网络服务器的日志时,日志会在几乎几分钟的延迟后得到更新。我已经证实它不是导致延迟的日志过程。使用curl和浏览器发出相同的http请求,我看到日志几乎立即更新。

    import UIKit

    import Alamofire



    Alamofire.request(.GET, "http://localhost:5010/asdf")
        .responseJSON { response in
            print ("Hello there in playground")
            print(response.request)  // original URL request
            print(response.response) // URL response
            print(response.data)     // server data
            print(response.result)   // result of response serialization

            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
    }

1 个答案:

答案 0 :(得分:3)

网络请求等延时事件的游乐场行为......最多是不可预测的。

尝试让操场知道它应该等待您的网络请求:

3.1416
3.14159
3.14159
3.141590000