title: swift http request can't get non-200 response
body: <p>I am using below swift code to make a http request. If the server response 200 OK response, swift can work properly. However, the completionHandler callback never get called until timeout when the server response other than 200 status. Is there any other setting on swift to prevent receiving other status response?</p>
  
  <pre><code>let urlStr = "http://xxxxx"
  let url = NSURL(string: urlStr)!
  let request = NSMutableURLRequest(URL: url)
  request.HTTPMethod = "post"
  let task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: {(data, response, error) in
      guard let _:NSData = data, let _:NSURLResponse = response where error == nil else {
                  // no response code
          print("response")
          return
      }
      print("get response from register service \(data) \(error)")         
  })
  task.resume()
  </code></pre>
  
  <p>If that happens, I get timeout error below:</p>
  
  <blockquote>
    <p>get login response nil error:Optional(Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=<a href="http://XXXXX" rel="nofollow">http://XXXXX</a>, NSErrorFailingURLKey=<a href="http://localhost:8080/nurse/login" rel="nofollow">http://localhost:8080/nurse/login</a>, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2103, NSLocalizedDescription=The request timed out.})</p>
  </blockquote>
  
  <p>Also I tested with curl command and I was able to get the response as below. So the server side works fine for me. I believe the problem is on the client side.</p>
  
  <pre><code>$ curl -i -X POST -d 'mobile=1234' http://localhost:8080/nurse/login
  HTTP/1.1 10029 
  Server: Apache-Coyote/1.1
  X-Application-Context: application
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Methods: *
  Access-Control-Allow-Headers: access_token
  Content-Type: text/plain;charset=UTF-8
  Content-Length: 18
  Date: Thu, 24 Mar 2016 02:39:09 GMT
  </code></pre>