iOS: How can i receive HTTP 401 instead of -1012 NSURLErrorUserCancelledAuthentication

Yes. Stop using the synchronous API. If you use the asynchronous delegate-based API then you have a lot more control over the connection. With this API, except in cases where an error is encountered before the HTTP header is received, you will always receive -connection:didReceiveResponse:, which gives you access to the HTTP header fields (encapsulated in an NSURLResponse object). You can also implement authentication using the relevant delegate methods if you are so inclined.

Leave a Comment