java代码中设置代理的方法:
1 使用URLConnection时
InetSocketAddress addr = null;
addr = new InetSocketAddress(ip,port);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
URLConnection uc = urlObject.openConnection(proxy);
2使用httpclient时
//设置代理访问和超时处理
HttpHost proxy = new HttpHost(ip, Integer.parseInt(port));
RequestConfig config = RequestConfig.custom().setProxy(proxy).setConnectTimeout(3000). setSocketTimeout(3000).build();
// 根据地址获取请求
HttpGet request = new HttpGet(urlNameString);//这里发送get请求
request.setConfig(config);
// 获取当前客户端对象
HttpClient httpClient = new DefaultHttpClient();
// 通过请求对象获取响应对象
System.out.println(request.getConfig());
HttpResponse response = httpClient.execute(request);
3 设置System相关的属性
//设置代理
System.setProperty("http.maxRedirects", "50");
System.getProperties().setProperty("proxySet", "true");
System.getProperties().setProperty("http.proxyHost", ip);
System.getProperties().setProperty("http.proxyPort", port);
这是一条华丽的分割线,对于HashMap的一些笔记
You are not suitable for the pair of laughing eyes frown
你那双爱笑的眼睛不适合皱眉