List of usage examples for org.apache.http.impl.client ProxyClient tunnel
public Socket tunnel(final HttpHost proxy, final HttpHost target, final Credentials credentials) throws IOException, HttpException
From source file:com.dlmu.heipacker.crawler.client.ProxyTunnelDemo.java
public final static void main(String[] args) throws Exception { ProxyClient proxyClient = new ProxyClient(); HttpHost target = new HttpHost("www.yahoo.com", 80); HttpHost proxy = new HttpHost("localhost", 8888); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd"); Socket socket = proxyClient.tunnel(proxy, target, credentials); try {/*from www . j a v a 2 s.c om*/ Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } finally { socket.close(); } }
From source file:com.cncounter.test.httpclient.ProxyTunnelDemo.java
public final static void main(String[] args) throws Exception { ProxyClient proxyClient = new ProxyClient(); HttpHost target = new HttpHost("www.google.com", 80); HttpHost proxy = new HttpHost("localhost", 1080); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd"); Socket socket = proxyClient.tunnel(proxy, target, credentials); try {/* w ww . j av a 2 s . c o m*/ Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } finally { socket.close(); } }
From source file:com.zhch.example.commons.http.v4_5.ProxyTunnelDemo.java
/** * ?? demo/* ww w . j a va 2s .co m*/ * * @throws Exception */ public final static void officalDemo() throws Exception { ProxyClient proxyClient = new ProxyClient(); HttpHost target = new HttpHost("www.yahoo.com", 80); HttpHost proxy = new HttpHost("localhost", 8888); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd"); Socket socket = proxyClient.tunnel(proxy, target, credentials); try { Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } finally { socket.close(); } }
From source file:com.zhch.example.commons.http.v4_5.ProxyTunnelDemo.java
/** * demo //from w w w .j av a 2 s .co m * * @throws Exception */ public final static void zhchModifyDemo() throws Exception { ProxyClient proxyClient = new ProxyClient(); HttpHost target = new HttpHost("pan.baidu.com", 80); // HttpHost proxy = new HttpHost("120.24.0.162", 80); HttpHost proxy = new HttpHost("127.0.0.1", 80); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("abc", "def"); System.out.println("before tunnel."); Socket socket = proxyClient.tunnel(proxy, target, credentials); System.out.println("after tunnel."); try { Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } finally { socket.close(); } }
From source file:io.undertow.server.handlers.HttpTunnelingViaConnectTestCase.java
@Test public void testConnectViaProxy() throws Exception { final HttpHost proxy = new HttpHost(DefaultServer.getHostAddress("default"), DefaultServer.getHostPort("default") + 1, "http"); final HttpHost target = new HttpHost(DefaultServer.getHostAddress("default"), DefaultServer.getHostPort("default"), "http"); ProxyClient proxyClient = new ProxyClient(); Socket socket = proxyClient.tunnel(proxy, target, new UsernamePasswordCredentials("a", "b")); try {/*from w ww. j a v a2 s .com*/ Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; boolean found = false; while ((line = in.readLine()) != null) { System.out.println(line); if (line.equals("MyHeader: MyValue")) { found = true; } } Assert.assertTrue(found); } finally { socket.close(); } }