[C#] 纯文本查看 复制代码 string code_cookie;
private void getcodebtn_Click(object sender, EventArgs e)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.hasyy.com/px/Index.asp",//URL这里都是测试 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
//Encoding = Encoding.Default,
Method = "get",//URL 可选项 默认为Get
};
HttpResult result = http.GetHtml(item);
item = new HttpItem()
{
URL = "http://www.hasyy.com/px/Code.asp",//URL必需项
Encoding = Encoding.Default,//编码格式(utf-8,gb2312,gbk)
Method = "get",//URL     可选项 默认为Get
ResultType = ResultType.Byte,
Cookie = result.Cookie.Replace("path=/", "")
};
result = http.GetHtml(item);
code_cookie += result.Cookie;
pictureBox1.Image = byteArrayToImage(result.ResultByte);
}
private void postbtn_Click(object sender, EventArgs e)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.hasyy.com/px/Index.asp",//URL 必需项
//Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Encoding = Encoding.UTF8,
Method = "post",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
KeepAlive = true,
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
Referer = "http://www.hasyy.com/px/",//来源URL 可选项
Postdata = "gid_1=202&User_Code=" + yzm.Text.Trim() + "&action=save",//Post数据 可选项GET时不需要写
ResultType = ResultType.String,//返回数据类型,是Byte还是String
//Cookie = code_cookie.Replace("path=/,", "").Replace("path=/", ""),//字符串Cookie 可选项
Cookie = code_cookie,
};
//得到HTML代码
HttpResult result = http.GetHtml(item);
//取出返回的Cookie
code_cookie += result.Cookie.Replace("path=/", "");
//返回的Html内容
string html = result.Html;
textBox2.Text = html;
textBox3.Text = code_cookie;
}
是这样操作吗,结果和之前一样 |