java設置代理IP訪問網站的方法
Java 技術具有卓越的通用性、高效性、平臺移植性和安全性,廣泛應用于PC、數據中心、游戲控制臺、科學超級計算機、移動電話和互聯網,同時擁有全球最大的開發者專業社群。以下是小編為大家搜索整理的java設置代理IP訪問網站的方法,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!
1.源碼
import java.io.BufferedInputStream;
import java.net.URL;
import java.net.URLConnection;
public class TestProxyIp {
public static void main(String args[]){
/pic/pic/p>
System.getProperties().setProperty("http.proxyHost", "218.26.204.66");
System.getProperties().setProperty("http.proxyPort", "8080");
System.out.println(getHtml("/pic/ip2city.asp")); /pic/p>
}
private static String getHtml(String address){
StringBuffer html = new StringBuffer();
String result = null;
try{
URL url = new URL(address);
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)");
BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
try {
String inputLine;
byte[] buf = new byte[4096];
int bytesRead = 0;
while (bytesRead >= 0) {
inputLine = new String(buf, 0, bytesRead, "ISO-8859-1");
【java設置代理IP訪問網站的方法】相關文章:
局域網ip設置方法10-28
java設置光標位置方法01-21
java設置cookie方法流程03-15
java環境變量的設置方法12-02
Ubuntu Linux系統下設置Static IP的方法02-09
關于java的訪問控制02-26
實現PHP實現限制IP訪問02-23
JAVA中IP和整數相互轉化的方法12-21
設置Java對話框字體的方法10-21