apache-httpclient-4.x

HttpEntity is deprecated on Android now, what's the alternative?

限于喜欢 提交于 2019-11-26 08:10:29
问题 With the release of Android 5.1, it looks like all the Apache http stuff has been deprecated. Looking at the documentation is useless; they all say This class was deprecated in API level 22. Please use openConnection() instead. Please visit this webpage for further details. Which is fine the first time you read it, but when EVERY class that was deprecated says that, it\'s not that helpful. Anyway, what are the alternatives for classes like HttpEntity , specifically StringEntity , and

How to prevent apache http client from following a redirect

落爺英雄遲暮 提交于 2019-11-26 08:07:27
问题 I\'m connecting to a remote server with apache http client. the remote server sends a redirect, and i want to achieve that my client isn\'t following the redirect automatically so that i can extract the propper header and do whatever i want with the target. i\'m looking for a simple working code sample (copy paste) that stops the automatic redirect following behaviour . i found Preventing HttpClient 4 from following redirect, but it seems i\'m too stupid to implement it with HttpClient 4.0

Apache HttpClient making multipart form post

六月ゝ 毕业季﹏ 提交于 2019-11-26 07:58:26
问题 I\'m pretty green to HttpClient and I\'m finding the lack of (and or blatantly incorrect) documentation extremely frustrating. I\'m trying to implement the following post (listed below) with Apache Http Client, but have no idea how to actually do it. I\'m going to bury myself in documentation for the next week, but perhaps more experienced HttpClient coders could get me an answer sooner. Post: Content-Type: multipart/form-data; boundary=---------------------------1294919323195 Content-Length:

Apache HTTP connection with Android 6.0 (Marshmallow)

纵饮孤独 提交于 2019-11-26 07:43:15
问题 Is there is any way to include the Apache library directly in Gradle to make it work with Android 6.0 ? I\'ve tried to include the libraries like that: compile \'org.apache.httpcomponents:httpcore:4.4.1\' compile \'org.apache.httpcomponents:httpclient:4.5\' And Android Studio couldn\'t manage to find the following import: import org.apache.http.auth.AuthenticationException; import org.apache.http.auth.Credentials; import org.apache.http.auth.MalformedChallengeException; import org.apache.http

Getting NoSuchFieldError INSTANCE org/apache/http/message/BasicHeaderValueParser

我是研究僧i 提交于 2019-11-26 07:33:40
问题 I\'m working on an app on Android. I\'m using httpcore 4.3.3. I get this when I try to use ContentType.parse(string) java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueParser; in class Lorg/apache/http/message/BasicHeaderValueParser; or its superclasses (declaration of \'org.apache.http.message.BasicHeaderValueParser\' appears in /system/framework/ext.jar) I\'ve done some googling and I understand why I\'m getting the error, but I\'m unsure

HttpClient 4.0.1 - how to release connection?

眉间皱痕 提交于 2019-11-26 06:28:00
问题 I have a loop over a bunch of URLs, for each one I\'m doing the following: private String doQuery(String url) { HttpGet httpGet = new HttpGet(url); setDefaultHeaders(httpGet); // static method HttpResponse response = httpClient.execute(httpGet); // httpClient instantiated in constructor int rc = response.getStatusLine().getStatusCode(); if (rc != 200) { // some stuff... return; } HttpEntity entity = response.getEntity(); if (entity == null) { // some stuff... return; } // process the entity,

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

北慕城南 提交于 2019-11-26 03:52:20
问题 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

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

这一生的挚爱 提交于 2019-11-26 02:07:20
问题 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? 回答1: Every library I can think of returns a stream. You could use IOUtils.toString() from Apache Commons IO to

How to ignore SSL certificate errors in Apache HttpClient 4.0

强颜欢笑 提交于 2019-11-26 00:45:40
问题 How do I bypass invalid SSL certificate errors with Apache HttpClient 4.0? 回答1: You need to create a SSLContext with your own TrustManager and create HTTPS scheme using this context. Here is the code, SSLContext sslContext = SSLContext.getInstance("SSL"); // set up a TrustManager that trusts everything sslContext.init(null, new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { System.out.println("getAcceptedIssuers ============="); return null; } public

Trusting all certificates using HttpClient over HTTPS

强颜欢笑 提交于 2019-11-25 23:56:29
问题 Recently posted a question regarding the HttpClient over Https (found here). I\'ve made some headway, but I\'ve run into new issues. As with my last problem, I can\'t seem to find an example anywhere that works for me. Basically, I want my client to accept any certificate (because I\'m only ever pointing to one server) but I keep getting a javax.net.ssl.SSLException: Not trusted server certificate exception. So this is what I have: public void connect() throws A_WHOLE_BUNCH_OF_EXCEPTIONS {