gpt4 book ai didi

iphone - 我想忽略证书验证,在哪里以及如何使用 XMLRPC Web 服务来做到这一点?

转载 作者:行者123 更新时间:2023-12-03 19:02:52 26 4
gpt4 key购买 nike

我正在访问 Web 服务,并在尝试连接时收到此错误(Web 服务是 XMLRPC,我使用 wordpress xmlrpc 源代码进行请求和处理响应):

Error Domain=NSURLErrorDomain Code=-1202 “此服务器的证书无效。您可能正在连接到一个冒充“**.org”的服务器,这可能会泄露您的 secret 信息信息面临风险。”

WebService 人们说忽略证书验证部分,所以如果有人知道如何做到这一点将对我有很大帮助。

经过一些建议,我使用了下面的 NSURLConnection 委托(delegate),但仍然出现同样的错误

 -(BOOL)connection:(NSURLConnection *)connection  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {  
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

最佳答案

目前Jay已经给出了正确的答案。但这两种方法现在已被弃用。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace // deprecated over iOS 5.0. Not even called in iOS 7.0

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge // deprecated over iOS 5.0. Not even called in iOS 7.0

因此,您可以使用该方法:

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodServerTrust) {
[[challenge sender] useCredential:[NSURLCredential credentialForTrust:[[challenge protectionSpace] serverTrust]] forAuthenticationChallenge:challenge];
}
}

我使用这段代码来克服下面列出的错误:

Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “app.*****.com” which could put your confidential information at risk.

关于iphone - 我想忽略证书验证,在哪里以及如何使用 XMLRPC Web 服务来做到这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3916574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com