首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在HTTP401之后,NSURLConnection不调用NSURLConnectionDelegate身份验证方法

在HTTP401之后,NSURLConnection不调用NSURLConnectionDelegate身份验证方法
EN

Stack Overflow用户
提问于 2013-06-19 23:35:55
回答 1查看 1K关注 0票数 0

我正在使用一个web服务,它将HTTP basic身份验证与NSURLConnection结合使用。在我的NSURLConnectionDelegate中,我实现了–[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]–[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]–[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:],但它们都没有被调用。

我尝试实现–[NSURLConnectionDelegate connectionShouldUseCredentialStorage:]来同时返回YESNO,但是没有效果。

I also ensured that my NSURLCredentialStorage was empty

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

怎样才能让NSURLConnection调用NSURLConnectionDelegate的身份验证回调?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-19 23:35:55

我的超文本传输协议服务器没有返回WWW-Authenticate标头。

我的服务器的响应:

代码语言:javascript
复制
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标头的服务器响应:

代码语言:javascript
复制
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标头。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17195438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档