I just wanted to know if any of you had any problems using java default HttpURLConnection class. Some kind of bug that made you switch to apache commons.
Or is it just the (ugly) interface that class exposes that justifies the birth of 3rd party http lib?
Disclosure: I heard some arguments against java.net having some serious problems, but I'm finding hard to believe that a class that is part of the java core distribution still has issues after several releases of the JDK
The things drive me to Apache HttpClient are,
You should use HttpClient 4 (Apache HTTP Components) now.
EDIT: The first problem has been discussed several times here. See,
HttpURLConnection.getResponseCode() returns -1 on second invocation
HttpURLConnection: What's the deal with having to read the whole response?
Even though the problem seems to be worse on Android, we saw the exact problems on J2SE.
The Android SDK says Prefer HttpURLConnection for new code.
Android includes two HTTP clients:
HttpURLConnection
andApache HTTP Client
. Both support HTTPS, streaming uploads and downloads, configurable timeouts, IPv6 and connection pooling. Apache HTTP client has fewer bugs in Android 2.2 (Froyo) and earlier releases. For Android 2.3 (Gingerbread) and later,HttpURLConnection
is the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. See the Android Developers Blog for a comparison of the two HTTP clients.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With