I would like to convert my response from the NSHTTPURLResponse type to String:
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) -> Void in
println("Response: \(response)")
var responseText: String = String(data: response, encoding: NSUTF8StringEncoding)
})
The line below outputs the response message to the console.
println("Response: \(response)")
But this line renders me an error: Extra argument 'encoding' in Call.
var responseText: String = String(data: response, encoding: NSUTF8StringEncoding)
How can I successfully convert this "response" into a String?
data
needs to be of typeNSData
but you are passing it anNSHTTPURLResponse
. The method that is called (and returns a string) isNSHTTPURLResponse
'sdescription
method. – Diametricallydata
to a string, notresponse
. – Subtleheaders { "Content-Length" = 4730; "Content-Type" = "text/html;charset=ISO-8859-1"; Date = "Sun, 25 Jan 2015 21:25:28 GMT"; Server = "Apache-Coyote/1.1"; "Set-Cookie" = "JSESSIONID=83A31742591DD2714A090FC53D55EEED; Path=/talkmore3/; Secure; HttpOnly"; }
– Proboscis