HttpClient 4.02を使用して、プロキシ経由で接続を作成し(CONNECTメソッドを使用)、リモートサーバーへの接続をトンネリングしています。HttpClientはこれに非常に便利ですが、私はAPIを初めて使用しSocket
、トンネル接続の基盤を取得する方法を理解できません。
// make sure to use a proxy that supports CONNECT
HttpHost target = new HttpHost("target.server.net", 443, "https");
HttpHost proxy = new HttpHost("some.proxy.net", 8080, "http");
// general setup
SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" and "https" protocol schemes, they are
// required by the default operator to look up socket factories.
supportedSchemes.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80));
supportedSchemes.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
// prepare parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params,
supportedSchemes);
DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpGet req = new HttpGet("/");
System.out.println("executing request to " + target + " via " + proxy);
HttpResponse rsp = httpclient.execute(target, req);
HttpEntity entity = rsp.getEntity();
これにより接続がSocket
適切に設定されますが、カスタムプロトコルを使用してtarget.server.netのサーバーと通信するために、基盤に到達する方法はありますか?