当前位置:编程学习 > JAVA >>

登录已经实现,如何自动发布内容

static final int TIMEOUT = 20000;// 连接超时时间
static final int SO_TIMEOUT = 20000;// 数据传输超时
static String UA = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1"
+ " (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1";
/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory
.getSocketFactory()));
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory
.getSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(
schemeRegistry);

cm.setMaxTotal(500);
cm.setDefaultMaxPerRoute(200);
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 50000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 50000);
params.setParameter(CoreProtocolPNames.USER_AGENT, UA);
params.setParameter("http.protocol.cookie-policy",CookiePolicy.BROWSER_COMPATIBILITY);

DefaultHttpClient client = null;
client = new DefaultHttpClient(cm, params);
String username = "wangyikan";
String passwd = "19900301";
//http://www.kfw001.com/news/member/index_do.php
//http://www.kfw001.com/home/ajax.php?act=dologin
HttpPost post = new HttpPost(
"http://www.kfw001.com/news/member/index_do.php");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("userid", username));
nvps.add(new BasicNameValuePair("pwd", passwd));
nvps.add(new BasicNameValuePair("dopost", "login"));
nvps.add(new BasicNameValuePair("fmdo", "login"));
nvps.add(new BasicNameValuePair("keeptime","31536000"));
nvps.add(new BasicNameValuePair("referer", "http://www.kfw001.com/"));
//nvps.add(new BasicNameValuePair("encoding", "UTF-8"));

try {
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
String url = "http://www.kfw001.com/home/main/scripts/default.js?t=1375185080";
result = HttpClientUtil.proyGetHttp(url, client);
System.out.println(result);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
Java 顶贴 发帖 自动发帖
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,