Java如何設置代理IP訪問網站
代理服務器(Proxy Server)是一種重要的'服務器安全功能,它的工作主要在開放系統互聯(OSI)模型的會話層,從而起到防火牆的作用。下面小編準備了關於Java如何設置代理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;
int bytesRead = 0;
while (bytesRead >= 0) {
inputLine = new String(buf, 0, bytesRead, "ISO-8859-1");
nd(inputLine);
bytesRead = (buf);
inputLine = null;
}
buf = null;
} finally {
e();
conn = null;
url = null;
}
result = new String(ring()()ytes("ISO-8859-1"), "gb2312")werCase();
}catch(Exception e){
tStackTrace();
return null;
}
html = null;
return result;
}
}
2.結果
-
SUN的JAVA程序員和開發員認證及考試
java程序員的認證SunCertifiedJAVAProgrammer(SCJP)課程:SL-275JAVA語言編程本課程使學員掌握如何使用標準JAVADevelopmentKit,V1.1(JDK)開發應用程序和applets。在本課程中您將學會JAVA語言的語法。如何使用JAVA來創建圖形用户接口(GUI),事件處理機制,例外處理...
-
Sun java認證考試答案
SUN認證是給網絡設計界建立的一套認證標準,Sun公司推出了Java以及Solaris技術認證方案。小編收集一些Sunjava認證考試真題答案,希望髮夾認真做題!1.Whatgetsprintedwhenthefollowingprogramiscompiledandrun?classTest{publicstaticvoidmain(Stringargs[]){inti;...
-
JAVA模擬試題及答案
Sun公司在推出Java之際就將其作為一種開放的技術。那麼java作為一種編程語言,你對java編程題有把握嗎?下面跟yjbys小編一起來看看吧!【程序1】題目:古典問題:有一對兔子,從出生後第3個月起每個月都生一對兔子,小兔子長到第三個月後每個月又生一對兔子,假如兔子都不死...
-
sun認證java程序員考試科目
un認證Java程序員考試旨在觀察您通過應用軟件分配進行復雜編程的能力,之後還要測試您完成編程所需的知識。下面是小編整理的'關於sun認證java程序員考試科目,歡迎大家參考!考試方式:全英文試題,以電腦作答,在授權的Prometric考試中心參加考試考試科目:SunCertifiedP...