java自动在中关村二手市场发布信息
类别: JAVA教程
/**
文件名:Zol.java
说明: 自动在中关村二手市场提交信息的程序
作者: 慈勤强
Email : cqq1978@Gmail.com
**/
import java.io.*;
import java.net.*;
class Zol
{
public String strCookie="";
private String login() //get cookie
{
String strUrl="http://www.zol.com.cn/user/login.php";
String strPwd="sssssssss"; //注册的用户名
String strUser="dddddddd"; //密码
String strPostData="User="+strUser+"&Password="+strPwd;
String strTmp;
try
{
URL url = new URL(strUrl);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(strPostData);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
wr.close();
rd.close();
StringBuffer sb=new StringBuffer("");
for (int i=0; ; i++)
{
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if(headerName!=null && headerName.equalsIgnoreCase("set-cookie"))
{
int j=headerValue.indexOf(";");
sb.append(headerValue.substring(0,j)+";");
}
if (headerName == null && headerValue == null)
{
break;
}
}
return sb.toString();
}
catch(Exception e)
{
return "err";
}
}
private String doPost()
{
String strUrl="http://flea.zol.com.cn/input_save.php";
String s1="game_board=0&"; //s1为提交的信息的详细说明,可以参考
s1=s1+"title=http://blog.csdn.net/cqq&";
s1=s1+"categoryNumber=5&";
s1=s1+"photo_file=&";
s1=s1+"subcategoryNumber=70&";
s1=s1+"areaNumber=2&";
s1=s1+"tradeModeNumber=1&";
s1=s1+"hownew=f&";
s1=s1+"price=111&";
s1=s1+"endTime=8&";
s1=s1+"brief=本信息由 http://blog.csdn.net/cqq 自动发出&";
s1=s1+"linkman=cqq&";
s1=s1+"phone=12345678&";
s1=s1+"email=sss@sss.net";
String ss;
StringBuffer s2=new StringBuffer("");
try
{
URL url = new URL(strUrl);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Cookie", login());
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(s1);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((ss=rd.readLine())!=null)
{
s2.append(ss+"/r/n");
}
wr.close();
rd.close();
return s2.toString();
}
catch(Exception e)
{
return "error";
}
}
public static void main(String[] args) throws Exception
{
Zol z=new Zol();
System.out.println(z.doPost());
}
}
文件名:Zol.java
说明: 自动在中关村二手市场提交信息的程序
作者: 慈勤强
Email : cqq1978@Gmail.com
**/
import java.io.*;
import java.net.*;
class Zol
{
public String strCookie="";
private String login() //get cookie
{
String strUrl="http://www.zol.com.cn/user/login.php";
String strPwd="sssssssss"; //注册的用户名
String strUser="dddddddd"; //密码
String strPostData="User="+strUser+"&Password="+strPwd;
String strTmp;
try
{
URL url = new URL(strUrl);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(strPostData);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
wr.close();
rd.close();
StringBuffer sb=new StringBuffer("");
for (int i=0; ; i++)
{
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if(headerName!=null && headerName.equalsIgnoreCase("set-cookie"))
{
int j=headerValue.indexOf(";");
sb.append(headerValue.substring(0,j)+";");
}
if (headerName == null && headerValue == null)
{
break;
}
}
return sb.toString();
}
catch(Exception e)
{
return "err";
}
}
private String doPost()
{
String strUrl="http://flea.zol.com.cn/input_save.php";
String s1="game_board=0&"; //s1为提交的信息的详细说明,可以参考
s1=s1+"title=http://blog.csdn.net/cqq&";
s1=s1+"categoryNumber=5&";
s1=s1+"photo_file=&";
s1=s1+"subcategoryNumber=70&";
s1=s1+"areaNumber=2&";
s1=s1+"tradeModeNumber=1&";
s1=s1+"hownew=f&";
s1=s1+"price=111&";
s1=s1+"endTime=8&";
s1=s1+"brief=本信息由 http://blog.csdn.net/cqq 自动发出&";
s1=s1+"linkman=cqq&";
s1=s1+"phone=12345678&";
s1=s1+"email=sss@sss.net";
String ss;
StringBuffer s2=new StringBuffer("");
try
{
URL url = new URL(strUrl);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Cookie", login());
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(s1);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((ss=rd.readLine())!=null)
{
s2.append(ss+"/r/n");
}
wr.close();
rd.close();
return s2.toString();
}
catch(Exception e)
{
return "error";
}
}
public static void main(String[] args) throws Exception
{
Zol z=new Zol();
System.out.println(z.doPost());
}
}
- 上一篇: Java应用问答
- 下一篇: java读取操作系统环境变量
-= 资 源 教 程 =-
文 章 搜 索