How to convert response.body from Vapor to String in Swift 3?

I use Vapor to try to get the XML file from another server, the problem is that I do not know how to convert the response body to a fast line.

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?

thank

+4
source share
1 answer

Oh well, I figured it out in the end.

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

}
+5
source

Source: https://habr.com/ru/post/1668075/


All Articles