我正在使用一个使用带有NSURLConnection
的HTTP基本身份验证的Web服务。在我的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
的身份验证回调?
答案 0 :(得分:1)
我的HTTP服务器未返回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
标题。