不知道大家有没遇到这样的问题,用软件POST发主题的时候,提示来路不正确。不知道怎么解决。请教下要怎么样解决这样的问题。下面这个是发布的参数,点击提交表单。 private void button2_Click(object sender, EventArgs e)
{
DateTime standerTime = new DateTime(1970, 1, 1);
long timestemp = (DateTime.Now.Ticks - standerTime.Ticks) / 10000000 - 8 * 60 * 60;// 时间戳
string title = textBox3.Text;
string content = richTextBox1.Text;
string sendUrl = "http://www.discuz.net/forum.php?mod=post&action=newthread&fid=23&extra=&topicsubmit=yes";
Encoding coding = Encoding.GetEncoding("gb2312");
string date = "subject="+content+"&message="+title+"&formhash=e4e2020a&usesig=1";
byte [] postcontent = coding.GetBytes(date);
HttpWebRequest send = (HttpWebRequest)WebRequest.Create(sendUrl);
send.KeepAlive = true;
send.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/xaml+xml, application/x-ms-xbap, application/x-ms-application";
send.Method = "POST";
send.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 677; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
send.ContentLength = postcontent.Length;
send.ContentType = "application/x-www-form-urlencoded";
CookieContainer sendcookie = new CookieContainer();
send.CookieContainer = sendcookie;
send.CookieContainer.Add(gCookieCollention);
Stream sendstream = send.GetRequestStream();
sendstream.Write(postcontent,0,postcontent.Length);
sendstream.Close();
HttpWebResponse result = (HttpWebResponse) send.GetResponse();
Stream resultStream = result.GetResponseStream();
StreamReader readresult = new StreamReader(resultStream, Encoding.GetEncoding("gb2312"));
string html = readresult.ReadToEnd();
if (html.IndexOf("楼主") > 0)
{
MessageBox.Show("发布成功");
}
else
{
MessageBox.Show("失败");
}
}
{
DateTime standerTime = new DateTime(1970, 1, 1);
long timestemp = (DateTime.Now.Ticks - standerTime.Ticks) / 10000000 - 8 * 60 * 60;// 时间戳
string title = textBox3.Text;
string content = richTextBox1.Text;
string sendUrl = "http://www.discuz.net/forum.php?mod=post&action=newthread&fid=23&extra=&topicsubmit=yes";
Encoding coding = Encoding.GetEncoding("gb2312");
string date = "subject="+content+"&message="+title+"&formhash=e4e2020a&usesig=1";
byte [] postcontent = coding.GetBytes(date);
HttpWebRequest send = (HttpWebRequest)WebRequest.Create(sendUrl);
send.KeepAlive = true;
send.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/xaml+xml, application/x-ms-xbap, application/x-ms-application";
send.Method = "POST";
send.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 677; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
send.ContentLength = postcontent.Length;
send.ContentType = "application/x-www-form-urlencoded";
CookieContainer sendcookie = new CookieContainer();
send.CookieContainer = sendcookie;
send.CookieContainer.Add(gCookieCollention);
Stream sendstream = send.GetRequestStream();
sendstream.Write(postcontent,0,postcontent.Length);
sendstream.Close();
HttpWebResponse result = (HttpWebResponse) send.GetResponse();
Stream resultStream = result.GetResponseStream();
StreamReader readresult = new StreamReader(resultStream, Encoding.GetEncoding("gb2312"));
string html = readresult.ReadToEnd();
if (html.IndexOf("楼主") > 0)
{
MessageBox.Show("发布成功");
}
else
{
MessageBox.Show("失败");
}
}
谢谢啦,我已经找到问题所在了。这里有一个新问题。。就是登陆之后抓到的页面是提示成功的框架,要等三秒才能转到首页,我要怎么样才能抓到首页的代码呢。。已经使用了 req.Referer = "http://www.discuz.net/"; 好像不成功,还是抓到一样的代码。。
<?xml version="1.0" encoding="gbk"?>
<root><![CDATA[<script type="text/javascript" reload="1">if(typeof succeedhandle_ls=='function') {succeedhandle_ls('http://www.discuz.net/', '欢迎您回来,King 用名,现在将转入登录前页面', {'username':'','usergroup':'King','uid':'12333','groupid':'11','syn':'1'});}hideWindow('ls');showDialog('欢迎您回来,King 用户名,现在将转入登录前页面', 'notice', null, function () { window.location.href ='http://www.discuz.net/'; }, 0, null, null, null, null, null, 2);</script><script type="text/javascript" src="http://www.discuz.net/xplus/api/uc.php?time=1323956437&code=4368K7wn7%2BFnjI5YC%2BxZCCyZ6C6CLbUj0MfWIZFvtbeuzlKBx32mPXf6RRb8%2BelR60igSa2P7qs9y%2FGvOOTLLB3nOK%2Bc9n0fX23QvS%2FJdXfp0eLJZhs9AOZUI2y9IKWQwnQHzw%2F9uvgBEPlOCE%2Bs6BpElj3siu38W7BfpiIoKFI" reload="1"></script><script type="text/javascript" src="http://uchome.developer.manyou.com/uchome/api/uc.php?time=1323956437&code=8735zDHSooBlmWzZ2b7OvMIuSB1CtvO46qmnLfrznl7neId6pFIXOUGAT9UJK57Kp9zksVdGna%2F3k8pzTF2j8kw9Z1ZA93AhdXw4WV0ToV%2BrIp8v5Va%2BSVKFpzwcCRCHn4cxN%2B6Pv2Y9b3%2Bwj%2FCSc%2FB7mepppopD1oNtVXrN1nw" reload="1"></script><script type="text/javascript" src="http://forum.developer.manyou.com/api/uc.php?time=1323956437&code=f239H7ktGOgAAbfx6V%2BokSWP0kZm%2FnGZjlXYsIBqEOLwNcnheUZ1iFJXzze9dxupVnTG5xlLls1VxjXWnDEKMuIv5ixHBRL4%2F4POlcCbUfaExtGAmxyk1qthZIYu1UHe%2BLSMHWl1izM7AHr%2BpgVHhYIM9KRk3ACLU1AVYzEPyeM" reload="1"></script><script type="text/javascript" src="http://www.discuz.net//api/uc.php?time=1323956437&code=fda5oWU2aLaCRreZ3L4qD5uDCad4emt14Xjz9AkaffqwUuxQn2vo32UkBXeGfZYvZO64gYYX6HO6idGDUAvAr2irw3Xjgx0WptxjmQU27gf8j4eUPQQx9kIGXTxtvN7VU0PxQCaD8W0ZJKOCFZZe6Syk4yFDYKztAhuEOmc5N3M" reload="1"></script>]]></root>