0

私は、HTTP 基本認証を使用する Web サービスを使用していますNSURLConnection。私のでは、 、 、および NSURLConnectionDelegateを実装しましたが、どれも呼び出されません。–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:]

と の両方を–[NSURLConnectionDelegate connectionShouldUseCredentialStorage:]返すように実装しようとしましたが、効果はありませんでした。YESNO

また、 myNSURLCredentialStorageが空であることも確認しました。

最後に、–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]、および –[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:]を実装する代わりに を実装–[NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge:]しましたが、どちらも呼び出されませんでした。

NSURLConnectioncallNSURLConnectionDelegateの認証コールバックを行うにはどうすればよいですか?

4

1 に答える 1

1

WWW-AuthenticateHTTP サーバーがヘッダーを返しません。

私のサーバーの応答:

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、手動でヘッダーを設定する必要があります。NSURLConnectionNSURLCredential

于 2013-06-19T15:35:54.960 に答える