I have this code:
public void WriteNewTopic(string subject, string message)
{
_webRequest = (HttpWebRequest)WebRequest.Create(this.Url + "newthread.php?do=newthread&f=" + AppsId);
_webRequest.Headers.Add("Cookie", this.Cookie);
_webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0";
_webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_webRequest.ContentType = "application/x-www-form-urlencoded";
_webRequest.Referer = this.Url + "viewforum.php?f=" + this.AppsId;
_webRequest.Headers.Add("Accept-Charset", "ISO-8859-2,utf-8;q=0.7,*;q=0.7");
_webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
_webRequest.Headers.Add("Accept-Language", "pl,en-us;q=0.7,en;q=0.3");
_webRequest.Method = "POST";
_webRequest.CookieContainer = _cookieContainer;
_webRequest.AllowAutoRedirect = false;
string values =
"do=postthread&f=" + AppsId +
"&securitytoken=1301767251-1a5636806411d07afb5cfde72c4f0978a1cf4415" +
"&wysiwyg=0&subject=" + subject +
"&message=" + message;
_webRequest.ContentLength = values.Length;
byte[] buffer = 开发者_如何学Pythonnew byte[256];
ASCIIEncoding ascii = new ASCIIEncoding();
buffer = ascii.GetBytes(values);
using (Stream stream = _webRequest.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
HttpWebResponse c;
try
{
c = (HttpWebResponse)_webRequest.GetResponse();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
if (c.Cookies.Count != 0)
{
this.Cookie = string.Empty;
foreach (Cookie cook in c.Cookies)
{
cook.HttpOnly = true;
Cookie = Cookie + cook + "; ";
}
}
}
But there's a security token in site source, but I can't get this token. Help me!
I dont know how to create new thread in vBulletin forum, but I think it would be more easier if you will use watin automation library
精彩评论