从NSUrlConnection didReceiveAuthenticationChallenge中提供有意义的错误 [英] Provide Meaningful Error from NSUrlConnection didReceiveAuthenticationChallenge
问题描述
我正在使用OWASP示例进行
最好提供一条类似警告:标识网站的公钥已更改...的文本消息。
另一个小的:在连接:didFailWithError:
,我不知道-1012是否是由于固定失败或另一个网络错误。所以我想提供的消息只是为证书失败,而不是其他-1012错误。
如何提供丰富的错误信息 code> [[challenge sender] cancelAuthenticationChallenge:challenge] (当连接:didReceiveAuthenticationChallenge:
失败时调用)。 NSURLConnectionDelegate协议参考和< a href =http://developer.apple.com/library/mac/#documentation/cocoa/reference/foundation/Protocols/NSURLAuthenticationChallengeSender_Protocol/Reference/Reference.html =nofollow noreferrer> NSURLAuthenticationChallengeSender协议参考
pre> NSString * alertMessage = [challenge.error localizedFailureReason];
以获取可读的错误信息。
请参阅 NSError 和 NSURLAuthenticationChallenge 。
I'm working with the OWASP sample for Certificate and Public Key Pinning. The sample uses random.org, and random.org recently got a new certificate. That means connection:didReceiveAuthenticationChallenge:
is failing. That is expected and good :)
However, the failure is displayed as "NSURLErrorDomain", with a code of -1012. That's not very helpful, and a user will not be able to do anything meaningful with it:
It would be much better to supply a message with text similar to "Warning: the public key identifying the website has changed...".
Another little nit: in connection:didFailWithError:
, I cannot tell if the -1012 is due to the pinning failure or another network error. So I would like to supply the message only for the certificate failure, and not other -1012 errors.
How does one supply "rich error information" to the call of [[challenge sender] cancelAuthenticationChallenge: challenge]
(which is called when connection:didReceiveAuthenticationChallenge:
fails). NSURLConnectionDelegate Protocol Reference and NSURLAuthenticationChallengeSender Protocol Reference do not mention how to do so.
Try to use
NSString * alertMessage = [challenge.error localizedFailureReason];
to get human readable error information.
See documentation for NSError and NSURLAuthenticationChallenge.
这篇关于从NSUrlConnection didReceiveAuthenticationChallenge中提供有意义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!