按apache官方javaAPI提供應該按如下方式建立代理
Socket socket = new Socket(new Proxy(Proxy.Type.SOCKS,new InetSocketAddress("10.161.32.26",8080)));
try {
socket.connect(new InetSocketAddress("http://www.baidu.com",80));
System.out.println(socket.isConnected());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
10.161.32.26區域網路代理ip,8080區域網路代理連接埠
但是很不幸,此種方法我試過,米有用,總是報錯java.net.SocketException: Software caused connection abort: recv failed;
socket【如果不符合,自己在封裝下吧】方式 //以下地址是Proxy 伺服器的地址 Socket socket = new Socket( "10.1.2.188" , 80 ); //寫與的內容就是遵循HTTP請求協議格式的內容,請求百度 socket.getOutputStream().write( new String( "GET http://www.baidu.com/ HTTP/1.1\r\n\r\n" ).getBytes()); byte [] bs = new byte [ 1024 ]; InputStream is = socket.getInputStream(); int i; while ((i = is.read(bs)) > 0 ) { System.out.println( new String(bs, 0 , i)); } is.close();
懶了,剩下的直接發連結
http://b-l-east.iteye.com/blog/1199237