我正在使用一个web服务,它将HTTP basic身份验证与NSURLConnection结合使用。在我的NSURLConnectionDelegate中,我实现了–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]、–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]和–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:],但它们都没有被调用。
我尝试实现–[NSURLConnectionDelegate connectionShouldUseCredentialStorage:]来同时返回YES和NO,但是没有效果。
I also ensured that my NSURLCredentialStorage was empty。
最后,我没有实现–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]、–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]和–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:],而是实现了–[NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge:],但也没有调用它。
怎样才能让NSURLConnection调用NSURLConnectionDelegate的身份验证回调?
发布于 2013-06-19 23:35:55
我的超文本传输协议服务器没有返回WWW-Authenticate标头。
我的服务器的响应:
HTTP/1.1 401 Unauthorized
Date: Wed, 19 Jun 2013 14:43:30 GMT
Server: Apache-Coyote/1.1
Expires: Wed, 19 Jun 2013 14:43:30 GMT
Vary: Accept-Encoding,User-Agent
Cache-Control: no-store, no-cache, must-revalidate, private, max-age=0
Content-Length: 0
Content-Type: text/plain另一个带有WWW-Authenticate标头的服务器响应:
HTTP/1.1 401 Authorization Required
Date: Wed, 19 Jun 2013 14:44:47 GMT
Server: Apache/2.2.17 (CentOS)
WWW-Authenticate: Basic realm="[LDAP/PROD] Active Directory"
Content-Length: 0
Connection: close
Content-Type: text/plain看起来NSURLConnection需要在其响应中包含WWW-Authenticate标头,以便调用NSURLConnectionDelegate的身份验证回调。
关于这一点我已经filed a radar了。请复制一份。
显然,由于NSURLConnection will not allow you to proactively authenticate with NSURLCredential,我将不得不手动设置Authorization标头。
https://stackoverflow.com/questions/17195438
复制相似问题