自己做的一个页面访问哦!如有什么不足请多提提意见。
以下是Java类
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class LinkHtml {
public static void main(String[] args) throws IOException {
HttpClient httpClient = new HttpClient();
//找到页面
GetMethod get = new GetMethod(
"http://172.18.1.36/safeplay/UserLogin.aspx");
int status = httpClient.executeMethod(get);
String s = get.getResponseBodyAsString();
//带用户名和密码登陆页面
PostMethod m = new PostMethod(
"http://172.18.1.36/safeplay/UserLogin.aspx");
m.addParameter("UserName", "user");
m.addParameter("PSW", "1111");
m.addParameter("__VIEWSTATE",
"dDwxNDI4MjgwODEyOzs+DXX+j4pn4z4ElAGGBEISkDUqpVs=");
m.addParameter("LogonButton", "登陆");
status = httpClient.executeMethod(m);
// System.out.println(status);
s = m.getResponseBodyAsString();
}}
方法中的所带的参数如"__VIEWSTATE"都是通过页面[b]MiniSniffer.exe[/b]工具这个是关键哦,又来他什么带参数的页面都可以查询, 查询到每登陆到一个页面所需要的参数哦!很简单的。
以下是Java类
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class LinkHtml {
public static void main(String[] args) throws IOException {
HttpClient httpClient = new HttpClient();
//找到页面
GetMethod get = new GetMethod(
"http://172.18.1.36/safeplay/UserLogin.aspx");
int status = httpClient.executeMethod(get);
String s = get.getResponseBodyAsString();
//带用户名和密码登陆页面
PostMethod m = new PostMethod(
"http://172.18.1.36/safeplay/UserLogin.aspx");
m.addParameter("UserName", "user");
m.addParameter("PSW", "1111");
m.addParameter("__VIEWSTATE",
"dDwxNDI4MjgwODEyOzs+DXX+j4pn4z4ElAGGBEISkDUqpVs=");
m.addParameter("LogonButton", "登陆");
status = httpClient.executeMethod(m);
// System.out.println(status);
s = m.getResponseBodyAsString();
}}
方法中的所带的参数如"__VIEWSTATE"都是通过页面[b]MiniSniffer.exe[/b]工具这个是关键哦,又来他什么带参数的页面都可以查询, 查询到每登陆到一个页面所需要的参数哦!很简单的。