日期:2014-05-20  浏览次数:20326 次

HttpWebRequest 站外提交搞不定
看过这个文章
http://hqt.cnblogs.com/archive/2005/10/08/250277.html

我现在想要用WINFORM自动登陆到DISCUZE论坛.
用SNIFFER截获的数据是这样的

提交登陆的页面是:http://bbs.cnaust.com/logging.php?action=login
帐号:solo   PWD:testpassword

E倷$@@麴E倷$@@麴

; 'G !P`頼?w4r€鵎v?
@??POST   /logging.php?action=login&   HTTP/1.1
Accept:   image/gif,   image/x-xbitmap,   image/jpeg,   image/pjpeg,   application/x-shockwave-flash,   application/vnd.ms-excel,   application/vnd.ms-powerpoint,   application/msword,   */*
Referer:   http://bbs.cnaust.com/logging.php?action=login
Accept-Language:   zh-cn
Content-Type:   application/x-www-form-urlencoded
UA-CPU:   x86
Accept-Encoding:   gzip,   deflate
User-Agent:   Mozilla/4.0   (compatible;   MSIE   7.0;   Windows   NT   5.1;   Maxthon;   .NET   CLR   2.0.50727)
Host:   bbs.cnaust.com
Content-Length:   185
Connection:   Keep-Alive
Cache-Control:   no-cache
Cookie:   cdb_sid=Irs1NE;   cdb_cookietime=2592000;   cdb_onlineindex=1;   cdb_sid=1qqvQM

formhash=3bd8bc0a&referer=index.php&loginfield=username&username=solo&password=testpassword&questionid=0&answer=&cookietime=2592000&loginmode=&styleid=&loginsubmit=%CC%E1+%26nbsp%3B+%BD%BBE4?@@?

请教  
                        Stream   newStream=myRequest.GetRequestStream();
                        //   Send   the   data.
                        newStream.Write(data,0,data.Length);
提交的data部分   如何写

------解决方案--------------------
string postData = "action=login ";
postData += "&username=solo ";
postData += "&PWD=testpassword ";

System.Text.Encoding encoding = System.Text.Encoding.GetEncoding( "GB2312 ");
byte[] data = encoding.GetBytes(postData);