See: Description
Class | Description |
---|---|
ApacheHttpClient4 |
A
Client that utilizes the Apache HTTP Client to send and receive
HTTP request and responses. |
ApacheHttpClient4Handler |
A root handler with Apache HTTP Client acting as a backend.
|
The client API with the Apache HTTP client can be used as follows to make simple GET and POST requests to a Web resource:
Client c = ApacheHttpClient4.create(); WebResource r = c.resource("http://host/base"); String s = r.get(String.class); s = r.post(String.class, s);
To support basic authentication with the user name "foo" and the password "bar" the following configuration may be utilized:
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials("foo", "bar") ); DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getProperties().put( ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider ); Client c = ApacheHttpClient4.create(config); WebResource r = c.resource("http://host/base"); String s = r.get(String.class); s = r.post(String.class, s);
Copyright © 2014. All Rights Reserved.