package com.hundred.httpclient;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class HttpClientDemo {
static final String LOGON_SITE = "jw.xxxx.com";
static final int LOGON_PORT = 80;
static final String USERNAME = "0000000";
static final String PASSWORD = "0000000";
static final String VIEWSTATE = "dDw1MjQ2ODMxNzY7Oz6kcKVV3SqRd9KtLpIdMU2sTzMXyw==";
static final String XXCJ = "xscj_gc.aspx?xh=";
public static void main(String[] args) throws Exception {
HttpClientDemo demo = new HttpClientDemo();
HttpClient client = demo.loginStatus();
GetMethod get = new GetMethod("/xs_main.aspx?xh=000000000");
client.executeMethod(get);
/*System.out.println(get.getResponseBodyAsString());
get.releaseConnection();*/
PostMethod post = new PostMethod("");
post.setRequestBody(new NameValuePair[] {
new NameValuePair(),
});
}
private HttpClient loginStatus() {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod post = new PostMethod("/default_ysdx.aspx");
NameValuePair data = new NameValuePair("__VIEWSTATE",VIEWSTATE);
NameValuePair name = new NameValuePair("TextBox1", USERNAME);
NameValuePair pass = new NameValuePair("TextBox2", PASSWORD);
NameValuePair cost = new NameValuePair("RadioButtonList1","%D1%A7%C9%FA");
NameValuePair tototo = new NameValuePair("Button1", "++%B5%C7%C2%BC++");
post.addParameter(tototo);
post.addParameter(name);
post.addParameter(pass);
post.addParameter(cost);
post.addParameter(data);
try {
client.executeMethod(post);
post.releaseConnection();
return client;
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}