winform模拟登录discuz网站 发帖

likaiiscoder 2013-09-27 09:28:55
现在的情况是我能模拟登录,能取到登录后的页面了 但是在发帖即POst数据时 一直说我没登录 哪位大神遇到过类似的情况
...全文
160 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
用的webbrower吗 我用这个做的可以保持浏览器信息
likaiiscoder 2013-09-27
  • 打赏
  • 举报
回复
是IE的问题?还是程序的问题
叫什么呢 2013-09-27
  • 打赏
  • 举报
回复
可能是会话状态没保存
likaiiscoder 2013-09-27
  • 打赏
  • 举报
回复
NONONO 是这句错了sendString += "Cookie:" + cookies + "\r\n\r\n"; 尼玛不知道为什么放在 sendString += "Connection:Keep-Alive\r\n\r\n";这个下面就好使了 晕倒
YeomanAmj 2013-09-27
  • 打赏
  • 举报
回复
请求来路不正确是因为 "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地址不正确
YeomanAmj 2013-09-27
  • 打赏
  • 举报
回复
你的cookie没有保存,保存下来后在post的时候把cookie传过去。有两种方法,一个是保存cookie字符串,一个是保存为cookiecontainer。例如:
登录的时候保存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没有试过。
likaiiscoder 2013-09-27
  • 打赏
  • 举报
回复
上面的sendstring 跟我用浏览器抓包的post数据 流是一样的 郁闷啊
likaiiscoder 2013-09-27
  • 打赏
  • 举报
回复
哪位大虾做过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; }

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧