0

我正在使用一个使用 HTTP 基本身份验证和NSURLConnection. 在我的NSURLConnectionDelegate, 中,我实现了–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:], –[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:],但没有一个被调用。

我已经尝试实现–[NSURLConnectionDelegate connectionShouldUseCredentialStorage:]同时返回YESand NO,但这没有效果。

我还确保 myNSURLCredentialStorage是空的。

最后,我没有实现–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:],而是实现–[NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge:]了 ,但也没有调用它。

我可以做些什么来进行NSURLConnectioncallNSURLConnectionDelegate的身份验证回调?

4

1 回答 1

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-AuthenticateNSURLConnectionDelegate

我已经为此提交了一份雷达。请复制它。

显然,我必须手动设置Authorization标头,因为NSURLConnection不允许您主动使用NSURLCredential.

于 2013-06-19T15:35:54.960 回答