I'm using the following function in Swift to connect to a PHP Script on a server and then process my request:
func pushtoserveronclick() {
var URL: NSURL = NSURL(string: "http://someurl.com/")!
var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMethod = "POST"
var bodyData = "data=something&version=\(appVersion)"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
println(response)
}
}
When I run the app I get this returned as the response:
<NSHTTPURLResponse: 0x14e53170> { URL: http://someurl.com/ } { status code: 200, headers {
Connection = "Keep-Alive";
"Content-Type" = "text/html";
Date = "Fri, 05 Dec 2014 06:23:23 GMT";
"Keep-Alive" = "timeout=2, max=100";
Server = Apache;
"Transfer-Encoding" = Identity;
How would I get the status code that is being returned so I can perform a check on it and tell whether or not it's a connection issue?