[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotNet4.Utilities;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string addpost(string a, string b, string c)
{
if (a == null)
{
return (b + "=" + c);
}
else
{
return (a + "&" + b + "=" + c);
}
}
private void button1_Click(object sender, EventArgs e)
{
HttpHelper http = new HttpHelper();
string p1 = null;
p1 = addpost(p1, "jumpurl", "http://bbs.mydigit.cn/");
p1 = addpost(p1, "step", "2");
p1 = addpost(p1, "ajax", "1");
p1 = addpost(p1, "pwuser", user);
p1 = addpost(p1, "pwpwd", pass);
p1 = addpost(p1, "lgt", "0");
HttpItem item = new HttpItem()
{
URL = "http://bbs.mydigit.cn/login.php",
Method = "post",
IsToLower = false,
Referer = "",
Postdata = p1,
Timeout = 100000,
ReadWriteTimeout = 30000,
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
ContentType = "application/x-www-form-urlencoded",
Allowautoredirect = true,
ProxyIp = "",
ResultType = ResultType.String
};
HttpResult result = http.GetHtml(item);
//登陆成功 返回值<?xml version="1.0" encoding="gbk"?><ajax><![CDATA[success [url]http://bbs.mydigit.cn/[/url]]]></ajax>
string html = result.Html;
string cookie = result.Cookie;
item = new HttpItem()
{
URL = "http://bbs.mydigit.cn/",
Method = "get",
IsToLower = false,
Cookie = cookie,
Referer = "",
Postdata = "",
Timeout = 100000,
ReadWriteTimeout = 30000,
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
ContentType = "application/x-www-form-urlencoded",
Allowautoredirect = true,
ResultType = ResultType.String
};
result = http.GetHtml(item);
html = result.Html;
//貌似不对头,和直接访问"http://bbs.mydigit.cn/"一样,不包含登陆用户信息
item = new HttpItem()
{
URL = "http://bbs.mydigit.cn/job.php?action=mutiupload",
Method = "get",
IsToLower = false,
Cookie = cookie,
Referer = "",
Postdata = "",//Post数据 可选项GET时不需要写
Timeout = 100000,
ReadWriteTimeout = 30000,
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
ContentType = "application/x-www-form-urlencoded",
Allowautoredirect = true,
ResultType = ResultType.String
};
result = http.GetHtml(item);
//通过浏览器登陆访问这个地址的时候,返回值是{"uid":"461845","step":2,"verify":"4f2785cb"}
//而我这里的返回值为{"uid":"","step":2,"verify":"abef30dd"},缺少UID的值,和没登陆一样
}
}
}