apache-httpclient-4.x

Creating a UrlEncodedFormEntity from a List of NameValuePairs throws a NullPointerException

孤人 提交于 2019-12-03 05:43:11
I'm creating a unit test to try out the servlet I just created. @Test public void test() throws ParseException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://localhost:8080/WebService/MakeBaby"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("father_name", "Foo")); nameValuePairs.add(new BasicNameValuePair("mother_name", "Bar")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = null; try { response = client.execute(post); } catch

Apache HttpClient and PEM certificate files

与世无争的帅哥 提交于 2019-12-03 04:05:25
I'd like to programmatically access a site that requires Client certificates, which I have in PEM files. In this application I don't want to add them to my keystore, use keytool, or openssl if I can avoid doing so. I need to deal with them directly in code. HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("https://my.secure.site.com/url"); // TODO: Specify ca.pem and client.pem here? HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager()

how to make Unirest(java) ignore certificate error

时光总嘲笑我的痴心妄想 提交于 2019-12-03 03:39:46
I am using Unirest (java version) to make GET and POST request.But I encounter a problem when accessing SSL encrypted site , since my program is behind a corporate network and the network admin setup a firewall mapping for me. For example foobar.com is mapped to 56.1.89.12:4444 . But when I make request to the address, I will received the following ssl certificate error: com.mashape.unirest.http.exceptions.UnirestException: javax.net.ssl.SSLException: hostname in certificate didn't match: <56.1.89.12> != <www.foobar.com> at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper

Why am I getting an exception javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated?

人走茶凉 提交于 2019-12-03 02:20:33
问题 I'm using Apache HttpComponents HttpClient(4.0.1) to make a HTTPS call, but I'm this exception as the response: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:345) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390) at org.apache.http.impl.conn.DefaultClientConnectionOperator

Apache HttpClient (4.1 and newer): how to do basic authentication?

ぐ巨炮叔叔 提交于 2019-12-03 02:14:45
问题 How do I add basic authentication for the default client of the httpClient library? I have seen examples where they use client.getCredentialProvider() , however I think all of this methods are for library version 4.0.1 or 3.x. Is there a new example of how to do this? Thanks a lot. 回答1: We do basic authentication with HttpClient , but we do not use CredentialProvider . Here's the code: HttpClient client = factory.getHttpClient(); //or any method to get a client instance Credentials

How to send parallel GET requests and wait for result responses?

我的未来我决定 提交于 2019-12-03 01:00:29
问题 I'm using apache http client within spring mvc 3.2.2 to send 5 get requests synchronously as illustrated. How can I send all of these asynchronously (in parallel) and wait for the requests to return in order to return a parsed payload string from all GET requests? public String myMVCControllerGETdataMethod() { // Send 1st request HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://api/data?type=1"); ResponseHandler<String> responseHandler = new

sending post data to https without ssl cert verification with apache httpClient client

时光总嘲笑我的痴心妄想 提交于 2019-12-02 21:24:34
I need to send post data to an https url using the apache HttpClient package, after sending the post data I need to retreive the html data. the post data that I'm sending is an XML string and the post data that I'm receving is an XML string. any information regarding the issue would be greatly appreciated. I googled and i found examples on the internet that uses DefaultHttpClient that now in version 4 is deprecated. so I'd like to know how to properly use the new version of the client. thanks. update public String sendPost(final String request, final String postData) throws

Force retry on specific http status code

给你一囗甜甜゛ 提交于 2019-12-02 19:38:11
Dealing with a specific website, sometimes I receive a http response with status code 403. I wanted to re-execute the request in such cases (because, in my specific situation, this server throws a 403 when it is actually overloaded). I tried to use a ResponseHandler together with a StandardHttpRequestRetryHandler , but it didn't work the way I hoped; I expected that throwing an exception in the ResponseHandler would trigger the StandardHttpRequestRetryHandler , but it does not seems to be the case. How can I achieve the desired functionality? Here is a sample code that illustrates my situation

Apache HttpClient (4.1 and newer): how to do basic authentication?

浪子不回头ぞ 提交于 2019-12-02 16:11:48
How do I add basic authentication for the default client of the httpClient library? I have seen examples where they use client.getCredentialProvider() , however I think all of this methods are for library version 4.0.1 or 3.x. Is there a new example of how to do this? Thanks a lot. We do basic authentication with HttpClient , but we do not use CredentialProvider . Here's the code: HttpClient client = factory.getHttpClient(); //or any method to get a client instance Credentials credentials = new UsernamePasswordCredentials(username, password); client.getState().setCredentials(AuthScope.ANY,

Why am I getting an exception javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated?

走远了吗. 提交于 2019-12-02 15:52:09
I'm using Apache HttpComponents HttpClient(4.0.1) to make a HTTPS call, but I'm this exception as the response: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:345) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148) at org.apache.http.impl.conn.AbstractPoolEntry