Base64 用于 Objective-C 中的基本身份验证
我在这里看到了一些类似的问题,但最近没有 - 所以我正在检查是否有任何变化。
我看到 didReceiveAuthenticationChallenge: 完全能够进行基本身份验证的 base64 编码,但是我需要发送基本身份验证 Authorization: 标头的服务器不会返回 HTTP401 并且(我假设?)不会导致 didReceiveAuthenticationChallenge:委托发送消息 - 所以我无法在那里建立凭证。
因此,我使用
[urlRequestForMyWorkspace addValue:@"基本" forHTTPHeaderField:@"授权"];
在调用 initWithRequest 之前:
但是 - 我找不到一个可以在 iphone 上运行的 Objective-C api 来从用户名和密码构建 base64 编码的凭据(除了编写一个,例如 http://www.cocoadev.com/index.pl?BaseSixtyFour)。
所以 - 这是唯一的方法,还是有其他方法可以强制使用标准 API 发送 http 基本身份验证凭据 - 如果服务器没有返回 401,这就是我的方法m 假设导致 didReceiveAuthnChallenge: 被发送?
谢谢, 理查德
I've seen some similar questions here on SO, but none recent - so i'm checking in to see if anything's changed.
I see that didReceiveAuthenticationChallenge: is perfectly capable of doing a base64 encode for basic authentication, but the server i need to send a basic auth Authorization: header to doesn't return an HTTP401 and (I assume?) doesn't cause the didReceiveAuthenticationChallenge: delegate message to get sent - so I can't build the credential in there.
So instead, I'm using
[urlRequestForMyWorkspace
addValue:@"Basic "
forHTTPHeaderField:@"Authorization"];
before calling initWithRequest:
But - I can't find an objective-c api that works on the iphone to build that base64 encoded credential from a username and pw (other than writing one e.g. http://www.cocoadev.com/index.pl?BaseSixtyFour).
So -
is that the only way, or is there some other way i can force the http basic auth credential to be sent using the standard apis - if the server isn't returning a 401, which is what i'm assuming causes didReceiveAuthnChallenge: to be sent?
thanks,
Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在您的服务器端代码上,因为它没有返回 401 =>
didReceiveAuthenticationChallenge: delegate
永远不会被调用。所以你被迫这样做(使用标头字段)Well the problem is on your server side code, since it is not returning 401 =>
didReceiveAuthenticationChallenge: delegate
will never be called. So you are forced to do it this way (using header fields)