winform模拟登录discuz网站 发帖 现在的情况是我能模拟登录,能取到登录后的页面了 但是在发帖即POst数据时 一直说我没登录 哪位大神遇到过类似的情况 winformdiscuz 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用的webbrower吗我用这个做的可以保持浏览器信息 哪位大虾做过discuz的登录发帖 为什么我现在能登录了 但是一直提示说您的请求来路不正确或表单验证串不符,无法提交 附上post代码 public string PostData2(string postURL, string postString,string cookies, string encoding) { try { string strHTML = "";//用来保存获得的HTML代码 Uri URI = new Uri(postURL); string sendString; sendString = "POST {0} HTTP/1.1\r\n"; sendString += "Host: {1}\r\n"; sendString += "User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; sendString += "Content-Type:application/x-www-form-urlencoded\r\n"; sendString += "Content-Length:{2}\r\n"; sendString += "Cookie:" + cookies + "\r\n\r\n"; sendString += "Accept: text/html, application/xhtml+xml\r\n"; sendString += "Referer: http://www.dz.com/forum.php?mod=post&action=newthread&fid=36&referer=http%3A//www.dz.com/forum.php%3Fmod%3Dforumdisplay%26fid%3D36"; sendString +="Accept-Language: zh-CN\r\n"; sendString +="Accept-Encoding: gzip, deflate"; sendString += "Cache-Control: no-cache"; sendString += "Connection:Keep-Alive\r\n\r\n"; sendString += "{3}\r\n"; sendString = string.Format(sendString, URI.PathAndQuery, URI.Host, postString.Length, postString); Byte[] ByteGet = Encoding.GetEncoding(encoding).GetBytes(sendString); IPAddress hostadd = Dns.GetHostEntry(URI.Host).AddressList[0]; IPEndPoint EPhost = new IPEndPoint(hostadd, 80); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Connect(EPhost); if (!s.Connected) { strHTML = "链接主机失败"; } s.Send(ByteGet, ByteGet.Length, SocketFlags.None); strHTML = Recv(s, Encoding.GetEncoding(encoding)); return strHTML; } 上面的sendstring 跟我用浏览器抓包的post数据 流是一样的 郁闷啊 你的cookie没有保存,保存下来后在post的时候把cookie传过去。有两种方法,一个是保存cookie字符串,一个是保存为cookiecontainer。例如:登录的时候保存cookieHttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), ReqEncoding)) str = reader.ReadToEnd(); CookieContainer SetCookie = new CookieContainer(); foreach (Cookie cookie in response.Cookies) { SetCookie.Add(cookie); }在post的时候,把cookie写进去request.CookieContainer = new CookieContainer();request.CookieContainer = SendCookie;还有,你的sendString并不是你要post的数据,而是要写进header里面的,post数据是在这里面的。用HttpWebRequest是这样的,socket没有试过。 请求来路不正确是因为"Referer: http://www.dz.com/forum.php?mod=post&action=newthread&fid=36&referer=http%3A//www.dz.com/forum.php%3Fmod%3Dforumdisplay%26fid%3D36";Referer后面的url地址不正确 NONONO 是这句错了sendString += "Cookie:" + cookies + "\r\n\r\n"; 尼玛不知道为什么放在 sendString += "Connection:Keep-Alive\r\n\r\n";这个下面就好使了 晕倒 请教一下WCF配置参数中maxConcurrentSessions与maxConnections的意思 求注释!求解释 如何取得”回收站”中文件的信息并操作”回收站”中的文件? bindingNavigator控件的问题 就10分了,希望能得到您的帮助!!! 正则表达式验证客户提供的数据的合法性是否高效 C#调用动态库 如何让一个窗体始终显示在另一个窗体之上? 循环标签的处理,在线等待。 想请问一下,如何通过单击一个按钮,改变wordwrap的值? C#如何监测电脑将要重启? 关于VS打开时报错
我用这个做的可以保持浏览器信息
public string PostData2(string postURL, string postString,string cookies, string encoding)
{
try
{
string strHTML = "";//用来保存获得的HTML代码 Uri URI = new Uri(postURL);
string sendString;
sendString = "POST {0} HTTP/1.1\r\n";
sendString += "Host: {1}\r\n";
sendString += "User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
sendString += "Content-Type:application/x-www-form-urlencoded\r\n";
sendString += "Content-Length:{2}\r\n";
sendString += "Cookie:" + cookies + "\r\n\r\n";
sendString += "Accept: text/html, application/xhtml+xml\r\n";
sendString += "Referer: http://www.dz.com/forum.php?mod=post&action=newthread&fid=36&referer=http%3A//www.dz.com/forum.php%3Fmod%3Dforumdisplay%26fid%3D36";
sendString +="Accept-Language: zh-CN\r\n";
sendString +="Accept-Encoding: gzip, deflate"; sendString += "Cache-Control: no-cache";
sendString += "Connection:Keep-Alive\r\n\r\n";
sendString += "{3}\r\n"; sendString = string.Format(sendString, URI.PathAndQuery, URI.Host, postString.Length, postString);
Byte[] ByteGet = Encoding.GetEncoding(encoding).GetBytes(sendString);
IPAddress hostadd = Dns.GetHostEntry(URI.Host).AddressList[0];
IPEndPoint EPhost = new IPEndPoint(hostadd, 80);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Connect(EPhost);
if (!s.Connected)
{
strHTML = "链接主机失败";
}
s.Send(ByteGet, ByteGet.Length, SocketFlags.None);
strHTML = Recv(s, Encoding.GetEncoding(encoding));
return strHTML;
}
登录的时候保存cookie
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), ReqEncoding))
str = reader.ReadToEnd();
CookieContainer SetCookie = new CookieContainer();
foreach (Cookie cookie in response.Cookies)
{
SetCookie.Add(cookie);
}
在post的时候,把cookie写进去request.CookieContainer = new CookieContainer();
request.CookieContainer = SendCookie;
还有,你的sendString并不是你要post的数据,而是要写进header里面的,post数据是在
这里面的。
用HttpWebRequest是这样的,socket没有试过。
"Referer: http://www.dz.com/forum.php?mod=post&action=newthread&fid=36&referer=http%3A//www.dz.com/forum.php%3Fmod%3Dforumdisplay%26fid%3D36";
Referer后面的url地址不正确