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

后端 未结 5 1109
一整个雨季
一整个雨季 2020-12-01 01:57

I have a problem similar to the one described in the link below.

NSHTTPURLResponse statusCode is returning zero when it should be 401

I use [NSURLConne

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 02:35

    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.

提交回复
热议问题