Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。以下是小编为大家搜索整理的设置代理IP访问网站的方法,希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网!
1.源码
import eredInputStream;
import ;
import onnection;
public class TestProxyIp {
public static void main(String args[]){
//roperties()roperty("proxySet", "true"); //如果不设置,只要代理IP和代理端口正确,此项不设置也可以
roperties()roperty("yHost", "");
roperties()roperty("yPort", "8080");
tln(getHtml("")); //判断代理是否设置成功
}
private static String getHtml(String address){
StringBuffer html = new StringBuffer();
String result = null;
try{
URL url = new URL(address);
URLConnection conn = Connection();
equestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; CLR 2.0.50727; CIBA)");
BufferedInputStream in = new BufferedInputStream(nputStream());
try {
String inputLine;
byte[] buf = new byte[4096];
int bytesRead = 0;
while (bytesRead >= 0) {
inputLine = new String(buf, 0, bytesRead, "ISO-8859-1");