我想忽略证书验证,在哪里以及如何使用XMLRPC Web服务? [英] I want to ignore certificate verification, where and how to do it with XMLRPC web service?

查看:138
本文介绍了我想忽略证书验证,在哪里以及如何使用XMLRPC Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am accessing a web service and getting this error when trying to connect( web service is XMLRPC and I am using wordpress xmlrpc source code for request and handling repsonse):

错误域= NSURLErrorDomain代码= -1202此服务器的证书无效。您可能正在连接到假装为 ** .org的服务器,这可能会提供您的机密信息风险很大。

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

WebService人员说要忽略证书验证部分,所以如果有人知道如何做,那将对我有很大的帮助。

WebService people are saying to ignore certificate verification part, so if someone has idea of how to do that will be of great help for me.

在一些建议之后我使用了下面的NSURLConnection委托,stil同样的错误

after some suggestion I used the below NSURLConnection delegate, stil same error

 -(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];
}


推荐答案

正如aegzorz所说, [NSURLRequest + setAllowsAnyHTTPSCertificate:forHost:] 是一个私有API,不应在生产代码中使用。由于它是一个私有API,因此它肯定会被App Store拒绝。处理不受信任证书的已发布方法是使用 NSURLConnection 委托方法 -connection:canAuthenticateAgainstProtectionSpace: -connection:didReceiveAuthenticationChallenge:

As aegzorz noted, [NSURLRequest +setAllowsAnyHTTPSCertificate:forHost:] is a private API and shouldn't be used in production code. Since it's a private API, it's a sure means of being rejected from the App Store. The published way to handle untrusted certs is to use the NSURLConnection delegate method -connection:canAuthenticateAgainstProtectionSpace: and -connection:didReceiveAuthenticationChallenge:.

你可以用这些API做很多事情,处理各种可想象的身份验证问题。我建议您学习Apple的示例代码 AdvancedURLConnections

There's a lot you can do with these APIs, handling every kind of authentication issue imaginable. I would suggest that you study Apple's sample code AdvancedURLConnections

这篇关于我想忽略证书验证,在哪里以及如何使用XMLRPC Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆