【发布时间】:2020-09-02 10:13:15
【问题描述】:
在我的一条路线中,我想从另一个站点获取 HTML。 https://docs.vapor.codes/4.0/content/ documents 支持 JSON 等,但我在原始 HTML 上找不到任何内容。
request.client.get(URI(string: "https://example.com/")).map { (response: ClientResponse) -> String? in
if response.status == .ok && response.content.contentType == .html {
return response.content... // How do I get raw html?
}
return nil
}
如何从客户端响应中获取原始 HTML?
【问题讨论】:
-
看看
response.body,这就是你要找的:) -
@imike
Cannot convert value of type 'ByteBuffer?' to specified type 'String'。如何将 HTML 作为字符串获取? -
String(buffer: byteBuffer) -
@imike 你考虑过添加这个作为答案吗?
-
不,我很高兴能帮上忙 :)
标签: swift request response vapor