AlamoFire 似乎没有做任何事情

AlamoFire doesn't appear to be doing anything

我正在尝试使用 AlamoFire 编写一个简单的爬虫,相对于服务器端 Vapor 后端。 AlamoFire 似乎已正确启动,但我没有从回调处理程序中获得任何操作。

import Routing
import Vapor
import Alamofire

public func routes(_ router: Router) throws {
    router.get("scrape") { req -> String in
        let stuff = Stuff(id: nil, sourcecode: "This saves to the database.")
        stuff.save(on: req)
        let q = Alamofire.request("http://sigh-fi.com/test.txt").responseString { response in

            // None of this prints to the terminal.
            print("Success: \(response.result.isSuccess)")
            print("Request: \(String(describing: response.response))")
            print("Result: \(String(describing: response.result))")
            print("String: \(String(describing: response.result.value))")

            // ideally I'd like to run...
            // let morestuff = Stuff(id: nil, sourcecode: response.result.value)
            let morestuff = Stuff(id: nil, sourcecode: "This doesn't save to the database, so I'm not even getting that far.")
            morestuff.save(on: req)
        }
        print(q) // prints "GET http://sigh-fi.com/test.txt" as expected
        return "okay"
    }
}

不幸的是,我无法判断这是 Vapor 问题、Alamofire 问题还是 Swift 问题。任何建议将不胜感激。

事实证明,Vapor 有自己的 HTTP 客户端库,而且似乎工作得很好。仍然不确定为什么 Alamofire 崩溃了,但这没有实际意义。

尼克,谢谢你的帮助。

https://docs.vapor.codes/3.0/http/client/