apache-httpclient-4.x

How do I use an SSL client certificate with Apache HttpClient?

人盡茶涼 提交于 2019-11-26 16:06:37
问题 In Python I was using requests like this: requests.put( webdavURL, auth=(tUsername, tPassword), data=webdavFpb, verify=False, cert=("/path/to/file.pem", "/path/to/file.key")) Easy as pie. Now I need to implement the same thing in Java using Apache HttpClient. How can I pass a client certificate when making requests using HttpClient? 回答1: I think the main difference is that in java, you usually put the key and the certificate to a key store and use it from there. Like you mention often people

Android project using httpclient --> http.client (apache), post/get method

孤人 提交于 2019-11-26 14:17:46
I'm doing a Get and Post method for an android project and I need to "translate" HttpClient 3.x to HttpClient 4.x (using by android). My problem is that I'm not sure of what I have done and I don't find the "translation" of some methods... This is the HttpClient 3.x I have done and (-->) the HttpClient 4.x "translation" if I have found it (Only parties who ask me problems) : HttpState state = new HttpState (); --> ? HttpMethod method = null; --> HttpUriRequest httpUri = null; method.abort(); --> httpUri.abort(); //httpUri is a HttpUriRequest method.releaseConnection(); --> conn.disconnect(); /

HttpClientBuilder basic auth

夙愿已清 提交于 2019-11-26 14:07:39
问题 Since HttpClient 4.3, I have been using the HttpClientBuilder. I am connecting to a REST service that has basic authentication. I am setting the credentials as follows: HttpClientBuilder builder = HttpClientBuilder.create(); // Get the client credentials String username = Config.get(Constants.CONFIG_USERNAME); String password = Config.get(Constants.CONFIG_PASSWORD); // If username and password was found, inject the credentials if (username != null && password != null) { CredentialsProvider

HttpClient 4 - how to capture last redirect URL

元气小坏坏 提交于 2019-11-26 12:36:29
问题 I have rather simple HttpClient 4 code that calls HttpGet to get HTML output. The HTML returns with scripts and image locations all set to local (e.g. <img src=\"/images/foo.jpg\"/> ) so I need calling URL to make these into absolute ( <img src=\"http://foo.com/images/foo.jpg\"/> ) Now comes the problem - during the call there may be one or two 302 redirects so the original URL is no longer reflects the location of HTML. How do I get the latest URL of the returned content given all the

java.net.SocketException: Too many open files

孤街醉人 提交于 2019-11-26 12:28:52
问题 I have a java app which runs just fine (on Ubuntu 10.04) for few hours until it hits \"java.net.SocketException: Too many open files\". The code for Sender.java can be found here Is it because I create a new instance of HttpPut and HttpPost for each thread? I\'m using apache-commons HTTPClient 4. Here\'s the exception log: java.net.SocketException: Too many open files at java.net.Socket.createImpl(Socket.java:414) at java.net.Socket.connect(Socket.java:544) at org.apache.http.conn.scheme

Apache HTTPClient SSLPeerUnverifiedException

南楼画角 提交于 2019-11-26 12:26:57
问题 Using Apache HttpClient 4.2.1. Using code copied from the form based login example http://hc.apache.org/httpcomponents-client-ga/examples.html I get an exception when accessing an SSL protected login form: Getting library items from https://appserver.gtportalbase.com/agileBase/AppController.servlet?return=blank javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Closing http connection at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397) at org.apache

Apache HttpClient 4.1 - Proxy Authentication

↘锁芯ラ 提交于 2019-11-26 10:58:30
问题 I\'ve been trying to configure the user and password for proxy authentication from the configured properties while using Apaches HttpComponent\'s httpclient, but with no success. All examples I have found refer to methods and classes that are no longer available, such as HttpState and setProxyCredentials . So, can anyone give me an example of how to configure the proxy credentials? 回答1: For Basic-Auth it looks like this: DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient

java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in Java application

末鹿安然 提交于 2019-11-26 10:27:01
问题 I have a Maven Java project that uses Mashape Unirest for sending HTTP requests to other URLs. I am currently writing an integration test (using TestNG ) that sends a normal HTTP request using Unirest. When I run the integration test through Maven (via the Failsafe plugin), the request is sent out successfully. However, when I try to run the integration test via Eclipse, I keep on getting the following error: FAILED: getCurrentTimeTest java.lang.NoSuchFieldError: INSTANCE at org.apache.http

How can I get an http response body as a string in Java?

元气小坏坏 提交于 2019-11-26 10:20:56
I know there used to be a way to get it with apache commons as documented here: http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HttpMethod.html and an example here: http://www.kodejava.org/examples/416.html but i believe this is deprecated. Is there any other way to make an http get request in java and get the response body as a string and not a stream? Every library I can think of returns a stream. You could use IOUtils.toString() from Apache Commons IO to read an InputStream into a String in one method call. E.g.: URL url = new URL("http://www.example.com/");

HTTPClient Example - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE

。_饼干妹妹 提交于 2019-11-26 09:53:15
问题 I am using HttpClient components from Apache for the following simple program and I see the below exception: Exception in thread \"main\" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:52) at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:56) at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:46) at org.apache.http