/**
文件名:HttpPost.java
描述: 有个网站老是给我发Email,所以就写了个小程序自动往留言本里面插入数据
作者:慈勤强
Email:cqq1978@Gmail.com
最后修改:2004-10-08
**/
import java.net.*;
import java.io.*;
class HttpPost extends Thread
{
private String strUrl;
private String strPostData;
public void setUrl(String str)
{
strUrl=str;
}
public String getUrl()
{
return strUrl;
}
public void setPostData(String str)
{
strPostData = str;
}
public String getPostData()
{
return strPostData;
}
public void doHttpPost()
{
String s,s1;
s=getUrl();
s1=getPostData();
if(s!=null)
{
try
{
URL url = new URL(s);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(s1);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
wr.close();
rd.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
public void run()
{
for(int i=1;i<20;i++)
{
HttpPost hp=new HttpPost();
hp.setUrl("http://www.hdptex.com/liuyan/savedata.asp");
hp.setPostData("txtname=茅山道人&txtEmail=s&txtTitle=不可不看&txtContent=http://blog.csdn.net/cqq");
hp.doHttpPost();
System.out.println("" + i);
}
}
public static void main(String[] args)
{
try
{
Thread[] t=new Thread[2];
for(int i=0;i<t.length;i++)
{
t[i]=new HttpPost();
t[i].start();
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}