AlamoFire似乎没有做任何事情

时间:2018-04-21 23:47:07

标签: alamofire vapor

我正在尝试使用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问题。任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

感谢您的帮助,尼克。

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