|
楼主 |
发表于 2013-5-17 21:04:22
|
显示全部楼层
站长苏飞 发表于 2013-5-17 20:29
和这个没有关系,还是你Cookie的问题,你发下代码吧,不看代码谁也不清楚是怎么回事
file:///C:\Documents and Settings\adimin\Application Data\Tencent\Users\1413902773\QQ\WinTemp\RichOle\O98%D}$39UF(ZGDZ63JGDA0.jpgprivate string Url = "http://www.37wan.com/";
private string PictureUrl = "http://passport.7fgame.com/ValidateCode.aspx?94737654";
HttpHelper httphelper = new HttpHelper();
HttpResult httpresult = new HttpResult();
HttpResult httpresult1 = new HttpResult();
private string PostString = string.Empty;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
httphelper.GetHtml(Url, null, null, -1, null, null, null, true, true, ref httpresult);//打开网站
PostString = "login_account="+textBox1.Text+"&password=" +textBox2.Text +"&remember_me=false" ;
httphelper.GetHtml("http://lhzs.37wan.com/login.php?action=login", "POST", null, -1, null, PostString, null, true, true, ref httpresult);//post登录
richTextBox1.Text = httpresult.ResultHtml;//返回html显示登录成功
httpresult1.Request_Cookie.Add(httpresult.Response_Cookie);//httpresult.Response_Cookie包含了所有的cookie
PostString = "";
httphelper.GetHtml("http://lhzs.37wan.com/login.php?action=to_sign", "POST", null, -1, null, PostString, null, true, true, ref httpresult1);//post签到
richTextBox1.Text = httpresult1.ResultHtml;//返回html显示 请先登录 我怀疑没有带上cookie
下面是我自己写的 获取html部分代码
if (request.Method == "POST")
{
ASCIIEncoding encoding = new ASCIIEncoding();//设置提交信息长度和设置提交内容
byte[] byte1 = encoding.GetBytes(InputData);
request.ContentLength = byte1.Length;
request.GetRequestStream().Write(byte1, 0, byte1.Length);
}
request.CookieContainer = HttpResult.Request_Cookie;//设置发送Cookie
HttpResult.HeadersSent = request.Headers;//获取请求体
HttpWebResponse response = (HttpWebResponse)request.GetResponse();//提交请求
HttpResult.HeadersReceived = response.Headers;//获取响应体
Stream stream = response.GetResponseStream();
StreamReader streamRead = new StreamReader(stream);
HttpResult.ResultHtml = streamRead.ReadToEnd();
HttpResult.Request_Cookie = request.CookieContainer;//请求体Cookie
HttpResult.All_Cookie = request.CookieContainer.GetCookies(HttpResult.Uri); //所有Cookie
HttpResult.Response_Cookie = response.Cookies;//响应体Cookie
stream.Close();
response.Close();
|
|