现在的情况是我能模拟登录,能取到登录后的页面了 但是在发帖即POst数据时 一直说我没登录 哪位大神遇到过类似的情况 winformdiscuz

解决方案 »

  1.   

    用的webbrower吗
    我用这个做的可以保持浏览器信息
      

  2.   

    哪位大虾做过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;
                }
      

  3.   

    上面的sendstring  跟我用浏览器抓包的post数据 流是一样的 郁闷啊
      

  4.   

    你的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没有试过。
      

  5.   

    请求来路不正确是因为
    "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地址不正确
      

  6.   

    NONONO 是这句错了sendString += "Cookie:" + cookies + "\r\n\r\n"; 尼玛不知道为什么放在 sendString += "Connection:Keep-Alive\r\n\r\n";这个下面就好使了  晕倒