Tag: apache httpclient 4.x

Java8,HttpClient,收到“收到致命警报:handshake_failure”

我们正在尝试访问以下URL(仅作为示例) https://broadly.vice.com/en_us/article/eating-out-as-a-feminist但我们收到“已收到致命警报:handshake_failure”。 我们使用的是JDK 1.8.60,HttpClient 4.3.6,并且已经将jce-policy替换为无限制策略。 激活-Djavax.net.debug =后我们收到: Allow unsafe renegotiation: false Allow legacy hello messages: true Is initial handshake: true Is secure renegotiation: false Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1 Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 for TLSv1 Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 for TLSv1 Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1 Ignoring unsupported cipher […]

从HttpClient 3.x迁移到4.x.

我们使用commons-httpclient-3.1编写了一些需要转换为4.1的代码。 我对此有点熟悉,现在正在阅读4.1 httpclient教程 。 我在这里看到了几个post(例如, 从HttpClient 3转换为4,但这是关于特定的构造)。 似乎应该有一些文档/示例显示如何将3.x的使用升级到4.x? 一个具体的例子:替换使用org.apache.commons.httpclient.HttpState

Peer未在java中进行身份validation

我已经去了几乎所有与此例外相关的post。 实际上我的问题是我有一个java应用程序,通过它我点击一个URL并从中得到响应。 命中URL的代码是: HttpGet getRequest = new HttpGet(“https://urlto.esb.com”); HttpResponse httpResponse = null; DefaultHttpClient httpClient = new DefaultHttpClient(); httpResponse = httpClient.execute(getRequest); 这里我得到javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 因此,经过一些谷歌搜索后,我才知道我可以在运行应用程序的java密钥库中导入证书。 所以我在密钥库中导入了证书,这段代码正常运行。 但我不想要这个解决方案,所以经过一些搜索后我才知道我可以使用TrustManager来做同样的事情,而无需将证书导入密钥库。 所以我编写了如下代码: @Test public void withTrustManeger() throws Exception { DefaultHttpClient httpclient = buildhttpClient(); HttpGet httpGet = new HttpGet(“https://urlto.esb.com”); HttpResponse response = httpclient.execute( httpGet ); HttpEntity httpEntity = response.getEntity(); InputStream […]

信任过期的证书

在与具有过期证书的https服务器通信时,我的客户端失败并出现以下错误。 虽然我们正在等待通过更新来修复服务器端,但我想知道我们是否可以通过将过期的证书添加到我们自己的信任存储来传递此错误? 这样我们就可以在等待续订证书的同时获得一些测试时间。 US has an end date Thu Sep 08 19:59:59 EDT 2011 which is no longer valid. [4/17/13 19:22:55:618 EDT] 00000021 SystemOut O WebContainer : 0, SEND TLSv1 ALERT: fatal, description = certificate_unknown [4/17/13 19:22:55:620 EDT] 00000021 SystemOut O WebContainer : 0, WRITE: TLSv1 Alert, length = 2 [4/17/13 19:22:55:620 EDT] 00000021 SystemOut […]

如何在httpclient 4.3+中更新HttpClient的设置?

在httpclient 4.3中,如果您尊重所有弃用,则必须使用HttpClientBuilder ( 此处提供文档)构建和配置HttpClient 。 这些方法是显式的,它们看起来很容易使用,并且HttpClient的界面很清晰。 但也许有点太多了。 在我自己的情况下,我必须inheritanceSpring的HttpComponentsHttpInvokerRequestExecutor ( 此处的文档)。 因此,我可以轻松获取HttpClient ,但我对此对象的所有了解都是它实现了接口。 由于客户端已经构建,并且我对它的实现一无所知,我无法访问AbstractHttpClient的setHttpRequestRetryHandler或addRequestInterceptor (虽然是的,我知道,它们已被弃用)。 那么,更新这个HttpClient的设置最简洁的方法是什么(重试处理程序和请求拦截器是我目前最关心的那些)? 我是不是该… …野蛮地将我的客户端投射到AbstractHttpClient ,希望我会一直收到这个实现? …在我的HttpInvokerRequestExecutor的构造函数中创建一个新的HttpClient ,并获得类似下面的示例? 我可能会补充说Spring的构造函数(至少在3.2.4中)也使用了httpclient 4.3中不推荐使用的方法。 使用这种策略会不会有任何副作用? ……做一些我还没有提出的建议吗? 自定义构造函数示例: public CustomHttpInvokerRequestExecutor() { super(); // will create an HttpClient // Now overwrite the client the super constructor created setHttpClient(HttpClientBuilder.custom(). … .build()); }

javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份validation的问题

我正在使用HttpClient-4.2.1并已在服务器上添加了证书,但我仍然收到以下错误。 我已经阅读了现有的问题,说要添加TrustManager( X509TrustManager ),但根据我的想法,这不是解决方案。 如果我错了,请纠正我。 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)

SSLHandshakeException:证书中的主机名不匹配

我正在编写一个系统,必须将一个多部分发布到服务器(一个名为ARX的第三方程序,当前在开发期间在localhost上运行),该服务器具有自签名证书。 我试图找到它的证书,但只能找到三个不同的jks文件; server.jks , servertrust.jks和serverca.jks 。 我试图使用每个jks文件的System.setProperty(“javax.net.ssl.trustStore”, “Program Files\\\\jksfile”) 。 然而; 当我这样做时,我收到以下错误: 证书中的主机名不匹配:!= 。 我已经在stackoverflow上浏览了大量类似的问题,试图了解如何解决这个问题,但我无法解决我的问题。 有什么建议么? 非常感谢所有帮助。

什么是apache中的SchemeRegistry以及何时应该使用它?

Apache HTTPClient包含SchemeRegistry类(org.apache.http.conn.scheme.SchemeRegistry) 什么是Scheme Registry? 什么时候可以使用? 如果我使用如下所示的方案注册表,它会产生什么影响 SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme(WEBSERVICE_URI_SCHEME, 80 ,PlainSocketFactory.getSocketFactory())); PoolingClientConnectionManager wsConnManager = new PoolingClientConnectionManager (registry);

Apache http客户端默认设置不适用于sni

初步问题 有没有最新的4.x apache http客户端我不知道的错误? 或者我缺少让sni工作的设置? 在同一个jvm上(在这种情况下为1.7.0_45)。 我运行以下两段代码来提取一个https url,它需要SNI才能正确连接。 第一段代码使用java内置的java.net。*方法,第二段代码使用org.apache.http。*(版本4.5)方法。 使用java.net。* public final class JavaNetHitApi extends BaseHitApi { @Override public JSONObject hitAPI(final String url) throws IOException { URL toUse = new URL(url); URLConnection conn = toUse.openConnection(); final String result = readToString(conn.getInputStream()); JSONObject toReturn = new JSONObject(result); return toReturn; } } 用org.apache.http进行处理。* public final class ApacheHttpHitApi extends […]

在HTTPClient 4.1中使用文件和字符串进行多部分POST

我需要创建包含字段的多部分POST请求: update[image_title] = String update[image] = image-data itself 。 正如你所看到的,两者都在称为“更新”的关联数组中。 我怎么能用HTTPClient 4.1来做,因为我只发现了这个库的3.x行的例子。 先谢谢你。