2011-04-02 118 views
1

我有这样的代码:如何在vBulletin论坛上使用c#创建新主题?

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 = new 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 + "; "; 
      } 
     } 
    } 

但有在网站源码的安全令牌,但我不能得到这个令牌。 帮帮我!

+0

好吧,我写的是工作,而不华廷库代码。谢谢。 – carck3r 2011-04-03 10:52:40

回答

1

我不知道如何在vBulletin论坛创建新的线程,但我认为它会更容易,如果你会使用watin自动化库