爬虫-java获取代理ip

欧阳小白 1年前 ⋅ 1399 阅读
package view;
 
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
//使用代理ip。项目不行
public class Iptest {
	public static void main(String[] args) throws MalformedURLException, IOException {
		// 使用java.net.Proxy类设置代理IP 114.243.67.243:8118
		Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("114.215.102.168", 8081));
		HttpURLConnection connection = (HttpURLConnection)new URL("http://www.baidu.com/").openConnection(proxy);  
		connection.setConnectTimeout(6000); // 6s  
		connection.setReadTimeout(6000);  
		connection.setUseCaches(false);  
		  
		if(connection.getResponseCode() == 200){  
		  System.out.println("代理ip连接成功");  
		}  
	}
}

 

http://mcj8089.iteye.com/blog/2196941 

链接附相关免费代理网址


全部评论: 0

    我有话说:

    咨询问题

    点击这里给我发消息

    淘宝咨询

    博主承接代做业务

    真·送云服务器

    咨询博主