當前位置:首頁 » 文件傳輸 » java訪問伺服器埠
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

java訪問伺服器埠

發布時間: 2023-04-15 20:36:06

⑴ 怎樣通過java使用socks代理訪問伺服器

packagetest;

importjava.io.IOException;
importjava.util.Date;

importorg.apache.commons.httpclient.HttpClient;
importorg.apache.commons.httpclient.HttpException;
importorg.apache.commons.httpclient.UsernamePasswordCredentials;
importorg.apache.commons.httpclient.auth.AuthScope;
importorg.apache.commons.httpclient.methods.PostMethod;

publicclasstest
{
publicstaticvoidmain(Stringargs[])
{
HttpClienthc=newHttpClient();

System.out.println("開始時間:"+System.currentTimeMillis());
for(inti=0;i<=100;i++)
{

try
{
//每10秒才會保存一次
Thread.sleep(12000);
}catch(InterruptedExceptione1)
{
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
Dated=newDate();
PostMethodpm=newPostMethod(
"http://www.tongaichina.com/post.asp?type=int&name=click&time="
+d.getTime());
try
{

//這里寫代理地址及埠
hc.getHostConfiguration().setProxy("代理地址",埠);

//這里是用戶名與密碼
=(
"用戶名","密碼");
hc.getState().setProxyCredentials(AuthScope.ANY,creds);

hc.executeMethod(pm);
System.out.println(pm.getResponseBodyAsString());
}catch(HttpExceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
System.out.println(i);
}
System.out.println("結束時間:"+System.currentTimeMillis());
}
}