Abstract: Netlib HTTP Client for Apache API - development is currently interrupted.
but you should use [Netlib Adapters] instead if possible
be careful - rest of this page because it is not up to date
IMPLEMENTATION STARTED BUT INTERRUPTED (package: org.silvertunnel.netlib.adapter.httpclient)
Use of the HttpClient 4.0:
Several examples are available from the HttpClient project: trunk/httpclient/src/examples/org/apache/http/examples/client/.
This is an modified examples of the HttpClient 4.0 use:
// the request URL final HttpHost requestedHost = new HttpHost("issues.apache.org", 80, "http"); HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); // Register the "http" protocol scheme, it is required // by the default operator to look up socket factories. SchemeRegistry schemeRegistry = new SchemeRegistry(); SocketFactory sf = MySocketFactory.getSocketFactory(); final int PORT_80 = 80; schemeRegistry.register(new Scheme("http", sf, PORT_80)); // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); // create http client ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, schemeRegistry); HttpClient httpClient = new DefaultHttpClient(ccm, params); // send request and receive response HttpResponse response = httpClient.execute(requestedHost, request); // read the response HttpEntity responseEntity = response.getEntity(); Header[] headers = response.getAllHeaders(); System.out.println(EntityUtils.toString(responseEntity));
Our own socket implementation will be encapsuleted in an own SocketFactory implementation called MySocketFactory.
/** * A own implementation of a SocketFactory. * * HttpClients usually uses PlainSocketFactory. */ public class MySocketFactory implements SocketFactory { public Socket createSocket() throws IOException { // ... } public Socket connectSocket( Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params ) throws IOException, UnknownHostException, ConnectTimeoutException { // ... } public boolean isSecure(Socket sock) throws IllegalArgumentException { // ... } }
Top: [Netlib], Next: [Netlib HTTP on High Latency Connections API]
Wiki: Netlib Adapters
Wiki: Netlib HTTP on High Latency Connections API
Wiki: Netlib HTTP
Wiki: Netlib HttpUtil
Wiki: Netlib