Apache HTTP client or URLConnection [duplicate]

Google has silently deprecated Apache HTTP client usage since Gingerbread: http://android-developers.blogspot.com/2011/09/androids-http-clients.html. And while they didn’t mark it with deprecated annotation, they suggest you to use HttpURLConnection for new applications as: it is where we [Google] will be spending our energy going forward. Personally I don’t like that decision and would rather stick to HttpClient 4.1+, … Read more

Preemptive Basic authentication with Apache HttpClient 4

If you are looking to force HttpClient 4 to authenticate with a single request, the following will work: String username = … String password = … UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); HttpRequest request = … request.addHeader(new BasicScheme().authenticate(creds, request));

How do Jersey-client and Apache HTTP Client compare?

These two things probably should not be compared directly. Jersey is a REST-client, featuring full JAX-RS implementation, neat fluent API and a powerfull filter stack. Apache Http Client is a HTTP-client, perfect in managing low-level details like timeouts, complex proxy routes and connection polling. They act on a different levels of your protocol stack. When … Read more

Android deprecated apache module (HttpClient, HttpResponse, etc.)

The method HttpClient was deprecated. You can now use the URLConnection as you can see in this example: private StringBuffer request(String urlString) { // TODO Auto-generated method stub StringBuffer chaine = new StringBuffer(“”); try{ URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestProperty(“User-Agent”, “”); connection.setRequestMethod(“POST”); connection.setDoInput(true); connection.connect(); InputStream inputStream = connection.getInputStream(); BufferedReader rd = … Read more

Fixing HttpClient warning “Invalid expires attribute” using fluent API

The default HttpClient has difficulty understanding the latest RFC-compliant headers. Instead of hiding the warning, just switch to a standard cookie spec like this (HttpClient 4.4+): HttpClient httpClient = HttpClients.custom() .setDefaultRequestConfig(RequestConfig.custom() .setCookieSpec(CookieSpecs.STANDARD).build()) .build();

Best Practice to Use HttpClient in Multithreaded Environment

Definitely Method A because its pooled and thread safe. If you are using httpclient 4.x, the connection manager is called ThreadSafeClientConnManager. See this link for further details (scroll down to “Pooling connection manager”). For example: HttpParams params = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme(“http”, PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, registry); … Read more

How to POST JSON request using Apache HttpClient?

Apache HttpClient doesn’t know anything about JSON, so you’ll need to construct your JSON separately. To do so, I recommend checking out the simple JSON-java library from json.org. (If “JSON-java” doesn’t suit you, json.org has a big list of libraries available in different languages.) Once you’ve generated your JSON, you can use something like the … Read more

How to handle invalid SSL certificates with Apache HttpClient? [duplicate]

https://mms.nw.ru uses a self-signed certificate that’s not in the default trust manager set. To resolve the issue, do one of the following: Configure SSLContext with a TrustManager that accepts any certificate (see below). Configure SSLContext with an appropriate trust store that includes your certificate. Add the certificate for that site to the default Java trust … Read more

Disable HttpClient logging

Update log4j.properties to include: log4j.logger.httpclient.wire.header=WARN log4j.logger.httpclient.wire.content=WARN Note that if Log4j library is not installed, HttpClient (and therefore JWebUnit) will use logback. In this situation, create or edit logback.xml to include: <configuration> <logger name=”org.apache” level=”WARN” /> <logger name=”httpclient” level=”WARN” /> </configuration> Setting the log level to WARN with Log4j using the package name org.apache.commons.httpclient in log4j.properties … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)