在iphone上实现https链接,post xml数据并接受返回的xml数据,用了NSMutableRequest NSURLConnection建立链接,但是有错误信息提示:NSURLErrorDomain error -1012 The certificate for this server is invalid. You might be connecting to a server that is pretending to be \U201c10.0.132.201\U201d which could put your confidential information at risk。链接的服务器是我自己配置的https服务器。
哪位大大知道,路过给点建议和解决方法,谢谢。

解决方案 »

  1.   

    这个地方应该是你的https的证书不能被客户端认证,那么你可以简单的用代码忽略这个错误,加入一个函数
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    在函数中写上
    if ([error code] != -1012) {
    return;
    }我自己没有试验环境,如果这个办法可行,请告知我,多谢!
      

  2.   

    谢谢楼上,我的问题解决了,就是添加了- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    这两个delegate method。
      

  3.   

    那两个代理方法我试验了,但是没有成功,双向认证的时候需要把本地证书中的cer文件信息读出来,然后验证服务器,如果验证成功则发自己的用户名和密码到服务器请求验证,最大的问题是本地的cer文件怎么读出来,请问楼主是怎么做的?
      

  4.   

    双向认证自带的NSURLConnection不支持,可以用ASIHTTPRequest 来完成