如何在 Vapor 3 中使用HTTPRequest
struct 发送 API 请求?
我尝试了以下代码的变体..
var headers: HTTPHeaders = .init()
let body = HTTPBody(string: a)
let httpReq = HTTPRequest(
method: .POST,
url: URL(string: "/post")!,
headers: headers,
body: body)
let httpRes: EventLoopFuture<HTTPResponse> = HTTPClient.connect(hostname: "httpbin.org", on: req).map(to: HTTPResponse.self) { client in
return client.send(httpReq)
}
编译错误Cannot convert value of type '(HTTPClient) -> EventLoopFuture<HTTPResponse>' to expected argument type '(HTTPClient) -> _'
我已经尝试过其他有效的代码变体。
let client = try req.make(Client.self)
let response: Future<Response> = client.get("http://example.vapor.codes/json")
我读了又读: