|
楼主 |
发表于 2018-6-8 11:04:33
|
显示全部楼层
我试了一下,还是同样的结果。。。。。
public partial class Form1 : Form
{
private String loginUrl = @"http://jkda.jxhfpc.gov.cn/";
private String actionUrl = @"http://jkda.jxhfpc.gov.cn/login/userLogin.action";
private String codeUrl = @"http://jkda.jxhfpc.gov.cn/login/imageCode.action";
private HttpHelper http = new HttpHelper();
private String cookie = "JSESSIONID={0}; BIGipServerPool_jkda={1}";
private String token_key= null;
private String token_value = null;
public Form1()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
HttpItem item = new HttpItem()
{
URL = loginUrl,
Method = "get",//URL 可选项 默认为Get
ResultType = ResultType.String
};
HttpResult result = http.GetHtml(item);
String str = result.Cookie;
String key = HttpHelper.GetBetweenHtml(result.Cookie, "JSESSIONID=", ";");
String sid = HttpHelper.GetBetweenHtml(result.Cookie, "BIGipServerPool_jkda=", ";");
cookie = string.Format(cookie, key, sid);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(result.Html);
token_key = doc.DocumentNode.SelectSingleNode("//input[@name='token_key']").Attributes["value"].Value;
token_value = doc.DocumentNode.SelectSingleNode("//input[@name='token_value']").Attributes["value"].Value;
item = new HttpItem()
{
URL = codeUrl,
Method = "get",//URL 可选项 默认为Get
Cookie = cookie,
ResultType = ResultType.Byte
};
Image img = http.GetImage(item);
this.pictureBoxCode.Image = img;
this.pictureBoxCode.Refresh();
}
private void buttonRefesh_Click(object sender, EventArgs e)
{
HttpItem item = new HttpItem()
{
URL = codeUrl,
Method = "get",//URL 可选项 默认为Get
Cookie = cookie,
ResultType = ResultType.Byte
};
Image img = http.GetImage(item);
this.pictureBoxCode.Image = img;
this.pictureBoxCode.Refresh();
}
private void buttonLogin_Click(object sender, EventArgs e)
{
String postData = string.Format("token_key={0}&token_value={1}&username={2}&password={3}&vercode={4}&online=on", token_key, token_value, this.textBoxUsername.Text.Trim(), this.textBoxPassword.Text.Trim(), this.textBoxVercode.Text);
HttpItem item = new HttpItem()
{
URL = actionUrl,//URL 必需项
Accept = "*/*",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
Method = "post",//URL 可选项 默认为Get
Cookie = cookie,
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",//返回类型 可选项有默认值
Postdata = postData,//Post要发送的数据
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
Console.Write(html);
MessageBox.Show(html);
}
} |
|