【问题标题】:How do I convert response.body from Vapor to String in Swift 3?如何在 Swift 3 中将 response.body 从 Vapor 转换为 String?
【发布时间】:2017-01-28 04:45:48
【问题描述】:

我正在使用 Vapor 尝试从另一台服务器获取 XML 文件,问题是我不知道如何将响应正文转换为快速字符串。

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?

谢谢

【问题讨论】:

    标签: vapor


    【解决方案1】:

    啊,好吧,我终于想通了。

    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) {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      相关资源
      最近更新 更多