用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心Java

java自动在中关村二手市场发布信息

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 18:54:42
/**
文件名: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());
}
}



Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:15,171.88000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号