【发布时间】:2011-12-13 08:14:57
【问题描述】:
我的应用程序中的 SSL 验证有点问题。正如我通过互联网在 FourSquare 的文档中找到的那样,他们建议像这样进行验证:SSL Calidation,但问题是我使用的是HttpsURLConnection,我想使用该类而不是DefaultHttpClient。因此,当我用HttpsURLConnection 替换getTolerantClient 中的客户端并尝试这样做时,它向我显示了一些错误:
public HttpsURLConnection getTolerantClient() {
HttpsURLConnection client = new HttpsURLConnection();
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) client.getConnectionManager().getSchemeRegistry().getScheme("https").getSocketFactory();
final X509HostnameVerifier delegate = sslSocketFactory.getHostnameVerifier();
if(!(delegate instanceof MyVerifier)) {
sslSocketFactory.setHostnameVerifier(new MyVerifier(delegate));
}
return client;
}
喜欢:
The method getConnectionManager() is undefined for the type HttpsURLConnection
&
The method getHostnameVerifier() is undefined for the type SSLSocketFactory
那么知道如何在我的情况下使用它吗? 提前致谢!
【问题讨论】: