写一个测试方法吧,看看到底生效没。
package com.test;import java.util.HashMap;import java.util.Map;public class TestHttp { public static void main(String[] args) { try { String url="http://www.baidu.com/"; Mapheaders = new HashMap (); headers.put("Accept", "text/html, */*; q=0.01"); headers.put("Accept-Encoding", "gzip, deflate, sdch"); headers.put("Accept-Language", "zh-CN,zh;q=0.8"); headers.put("Referer", url); headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0"); String result=HttpClientUtil.getWithProxy(url, headers, "UTF-8"); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } }}
运行一下,控制台的打印如下:
2016-05-26 21:42:05 26 process one socket : /192.168.1.101:570132016-05-26 21:42:05 26 user login success !2016-05-26 21:42:05 26 proxy header >> [5, 1, 0, 3]2016-05-26 21:42:05 26 connect www.baidu.com:802016-05-26 21:42:06 29 process one socket : /192.168.1.101:570152016-05-26 21:42:06 29 user login success !2016-05-26 21:42:06 29 proxy header >> [5, 1, 0, 3]2016-05-26 21:42:06 29 connect www.baidu.com:4432016-05-26 21:42:06 29 close socket, system cleanning ... /192.168.1.101:57015 2016-05-26 21:42:06 26 close socket, system cleanning ... /192.168.1.101:57013
成功啦,socks服务能够验证通过,并返回咯。