ios下https代理访问证书问题
2015-01-22 13:44
477 查看
在ios下,需要打开https链接,但是如果其中使用了代理访问,则会被默认返回证书验证错误,无法正常访问
通常是在国内访问国外facebook的情况下
这是因为
https访问的时候,会验证一次证书,如果用了代理,证书验证的时候会被认为有风险,则会拒绝掉连接
也就是为了避免中间人攻击而做的限制
这里可以考虑先用NSURLConnection创建一个https连接,让本次针对目标地址的连接在验证时忽略证书,就可以保证之后的连接再也没证书验证问题了
不过这个最好看看最新的sdk支不支持了。。
通常是在国内访问国外facebook的情况下
这是因为
https访问的时候,会验证一次证书,如果用了代理,证书验证的时候会被认为有风险,则会拒绝掉连接
也就是为了避免中间人攻击而做的限制
这里可以考虑先用NSURLConnection创建一个https连接,让本次针对目标地址的连接在验证时忽略证书,就可以保证之后的连接再也没证书验证问题了
NSString* strUrl = [NSString stringWithFormat:@https://graph.facebook.com/me]; NSURLRequest* reqUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:strUrl]]; NSURLConnection* conn = [NSURLConnection connectionWithRequest:reqUrl delegate:self]; [conn start]; - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"connection didFailWithError result: %@", error); } - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection { return NO; } - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { //第一次验证通过,之后取消验证 if ([challenge previousFailureCount] ==0) { NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; } else { [[challenge sender] cancelAuthenticationChallenge:challenge]; } } // Deprecated authentication delegates. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; } - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { //第一次验证通过,之后取消验证 if ([challenge previousFailureCount] ==0) { NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; } else { [[challenge sender] cancelAuthenticationChallenge:challenge]; } } - (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { //做你需要做的事情 }
不过这个最好看看最新的sdk支不支持了。。
相关文章推荐
- ios https访问自建证书时遇到的问题
- Cordova下自签名证书无法访问https问题(IOS和Android)
- iOS UIWebView 访问https 绕过证书验证的方法
- IOS HTTPS证书问题
- iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS
- IE内核浏览器访问https网站出现证书问题
- 使用 httpclient 访问https接口问题(无证书访问https接口)
- iOS UIWebView 访问https绕过证书验证的方法
- iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS
- 访问HTTPS时SSL/TLS证书拒绝问题 : unable to find valid certification path to requested target
- 关于ios项目绕过证书访问https
- HTTPS访问站点,出现证书问题解决(转载)
- iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS
- iOS实用技巧 - AFNetworking安全的使用自签证书访问HTTPS
- ios项目绕过证书访问https程序
- ios项目绕过证书访问https程序
- ios项目绕过证书访问https程序
- HTTPS跨域访问时,证书导致的问题
- iOS开发——https访问后台+证书
- iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS