2011-04-02 81 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自動化庫