如何在 Swift 3 中将 response.body 从 Vapor 转换为 String?
How do I convert response.body from Vapor to String in Swift 3?
我正在使用 Vapor 尝试从另一台服务器获取 XML 文件,问题是我不知道如何将响应正文转换为 swift 字符串。
let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")
let bodyBytes = bikesResponse.body
let string = String(bytes) // <-- WHAT DO I DO HERE?
谢谢
啊,好的,我终于想通了。
let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")
if let bodyBytes = bikesResponse.body.bytes {
let string = String(bytes: bodyBytes, encoding: String.Encoding.utf8) {
}
我正在使用 Vapor 尝试从另一台服务器获取 XML 文件,问题是我不知道如何将响应正文转换为 swift 字符串。
let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")
let bodyBytes = bikesResponse.body
let string = String(bytes) // <-- WHAT DO I DO HERE?
谢谢
啊,好的,我终于想通了。
let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")
if let bodyBytes = bikesResponse.body.bytes {
let string = String(bytes: bodyBytes, encoding: String.Encoding.utf8) {
}