- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我一直在使用以下代码连接到谷歌的一项服务。这段代码在我的本地机器上运行良好:
HttpClient client=new DefaultHttpClient();
HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");
post.setEntity(new UrlEncodedFormEntity(myData));
HttpResponse response = client.execute(post);
我把这段代码放在了一个生产环境中,它阻止了 Google.com。根据要求,他们通过允许我访问 IP 来允许与 Google 服务器通信:74.125.236.52 - 这是 Google 的 IP 之一。我也编辑了我的主机文件以添加此条目。
我仍然无法访问 URL,我想知道为什么。所以我把上面的代码换成了:
HttpPost post = new HttpPost("https://74.125.236.52/accounts/ClientLogin");
现在我收到这样的错误:
javax.net.ssl.SSLException: hostname in certificate didn't match: <74.125.236.52> != <www.google.com>
我猜这是因为 Google 有多个 IP。我不能要求网络管理员允许我访问所有这些 IP - 我什至可能无法获得整个列表。
我现在该怎么办? Java级别是否有解决方法?还是完全掌握在网络人手中?
最佳答案
您也可以尝试设置 HostnameVerifier,如 here 所述。 .这对我来说可以避免这个错误。
// Do not do this in production!!!
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new DefaultHttpClient();
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
// Set verifier
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
// Example send http request
final String url = "https://encrypted.google.com/";
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost);
关于Java SSLException : hostname in certificate didn't match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7256955/
在 Android Studio 中,当我尝试通过 SDK 管理器更新大型 SDK 时,我不断收到以下错误: SSLException: Connection has been shutdown:
我只是集成 Frimi 支付网关。第一步我尝试生成访问 token ,生成 token 后将调用支付链接。但我收到错误:- SSLException:连接已被对等方关闭。 public void
我发布了 this issue我可以解决它从 WebLogic startups 参数中删除下一个: -Djsse.enableSNIExtension=false 谁能解释一下? 最佳答案 参数 -
我的类(class)有一个简短的任务,即扩展一个简单的 Java 服务器以在 Ubuntu 上支持 SSL。 好的,首先,我这样做了: 私有(private)静态 SSLServerSocketFac
我打算为 Android 应用程序使用 GCM 功能。我设置了正确的 Android 应用程序和部署在本地主机上的后端服务。 一切都很好,通知显示在我的测试设备上。接下来我尝试将服务部署到具有真实 I
所以我想通过 https 测试一下。问题是我得到这个: Error getting response; javax.net.ssl.SSLException Received Fatal alert:
我将我的文件从 android 上传到 aws 服务。我是这样配置的: AwsMetadata awsMetadata = resultData.getParcelable(Params.Comm
我尝试向 Web 服务发送 https 请求,在几次成功尝试后,我开始不断收到此错误。这个错误是什么意思,为什么它会在第一次发生。 javax.net.ssl.SSLException: java.l
我是 React Native 的新手,一直在尝试一两个示例。当我尝试在我的 Mac 上构建 Android“电影”示例时,出现以下错误: ./gradlew :Examples:Movies:and
这个问题已经有答案了: javax.net.ssl.SSLException: Received fatal alert: protocol_version (15 个回答) 已关闭 7 年前。 我试
我正在尝试在 Android 客户端上使用自定义证书实现 SSL 连接。如果我尝试使用我编写的普通 Java 程序连接到同一台服务器(我在其中使用系统参数导入 keystore ),一切正常。此外,如
当我向 Google 云消息传递中心发送新的推送通知时,有时会出现问题。我正在使用可用的 Google 库 here .我正在使用 Tomcat 7.0.35 和 bouncycaSTLe 1.46。
我需要在服务器启动时使用 jax-rs 访问 https URL 以获取一些唯一的 session key 。但是,一旦 session 过期,我将再次触发对该 URL 的点击并取回我的 sessio
我正在使用 Android-Query 进行 HTTP 调用,并且不断收到随机的 SSLExceptions,如下所示: AQuery(7746): javax.net.ssl.SSLExceptio
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: SSL handshake alert: unrecognized_name error since upg
从昨天开始,我无法从 JBoss EAP 6.2 连接到我本地开发机器上的 MicroSoft SQLServer (v11.1.3000.0)。 SQLServer 现在想要使用 SSL 进行连接。
我正在创建一个 web 项目..我已经为此配置了 jdbc 领域..我需要将 java servlet 连接到 mysql 数据库.. private static String JDBC_DRIVE
当使用 Android 的 HttpUrlConnection 库发出 HTTPS 请求时,我有时会看到抛出以下异常: javax.net.ssl.SSLException: SSL handshak
我一直在使用以下代码连接到谷歌的一项服务。这段代码在我的本地机器上运行良好: HttpClient client=new DefaultHttpClient(); HttpPost post = ne
我有一个 Spring Boot 后端项目。我想使用我的 ssl 证书。 这是我的 application.properties 文件。 我使用 mycert.cert 和 mycert.key 创建
我是一名优秀的程序员,十分优秀!