⑴ 怎样通过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());
}
}