How can I use the latest version of HttpComponents on Android?

I used the HttpComponents library that Android comes with. I wrote 2 classes to send parameters with GET and POST and get InputStream or String from the server. Everything worked fine: every download in the stream, start, pause, resume ... But today I started two downloads at the same time, and none of them finished.

I have a googled solution, and I have seen that Android comes with HttpCore 4.0-beta2. Yes, he is very old. It was released on July 1, 2008, and Android has not updated it since ...

I rewrote my classes, but now I use HttpURLConnection, and I can upload two files at the same time.

Well, that was a warning to you if you plan to use the HttpComponents on Android. Now my question. I want to import a new version 4.1 into my project. I added banks to the constructed path, but now, how can I use these banks if the new (4.1) and old (beta2, 4.0) packages are the same?

Thank.

solvable
You must create DefaultHttpCLinet using ThreadSafeClientConnManager:

HttpParams parameters = new BasicHttpParams ();
HttpProtocolParams.setVersion (parameters, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset (parameters, HTTP.UTF_8);
HttpProtocolParams.setUseExpectContinue (parameters, false);
ConnManagerParams.setMaxTotalConnections (parameters, MAX_CONNECTIONS);

SchemeRegistry schReg = new SchemeRegistry ();
schReg.register (new Scheme ("http", PlainSocketFactory.getSocketFactory (), 80));

client = new DefaultHttpClient (new ThreadSafeClientConnManager (parameters, schReg), parameters);

UPDATE . You can also use AndroidHttpClient. With this class you do not need to use ThreadSafeClientConnManager

AndroidHttpClient client = AndroidHttpClient.newInstance ("Android");

Additional Information

+3
source share
1 answer

But today I started two downloads at the same time, and none of them finished.

HttpClient . ThreadSafeClientConnManager. HttpClient.

googled, , Android HttpCore 4.0-beta2. , . 1 2008 , Android ...

https://android.googlesource.com/platform/external/apache-http

, "01 2008 " .

, HttpURLConnection, .

HttpClient.

, (4.1) (beta2, 4.0) ?

.

+3

Source: https://habr.com/ru/post/1795474/


All Articles