2010-01-04 128 views
0

我創建一個嘰嘰喳喳客戶端沒有從頭開始,在我的64位機器在家裏我可以發佈罰款沒問題,但在我的32位筆記本電腦我得到一個錯誤417時我來發布推文。Twitter的c#客戶端無法發佈,由於錯誤417

我能讀的鳴叫很好,只是發佈,這似乎是一個問題,我也把其中的一些人說,從沒有任何的運氣accuring停止錯誤以下

 System.Net.ServicePointManager.Expect100Continue = false; 

我不確定什麼做下一個有沒有其他人有任何想法?發佈代碼如下。

感謝亞光

 string aUrl = "http://twitter.com/statuses/update.xml"; 

     client.Credentials = new NetworkCredential(_username, _password); 

     System.Net.ServicePointManager.Expect100Continue = false; 

     byte[] tweetBytes = System.Text.Encoding.UTF8.GetBytes("status=" + tweet); 

     client.UploadData(aUrl,tweetBytes); 

     return true; 
+1

我知道這是不是你的問題,但我會去了解一下TweetSharp這裏http://tweetsharp.com/發現 – 2010-01-04 20:54:55

+0

感謝,但希望從頭開始創建一切。學習曲線的一部分 – 2010-01-04 20:56:13

回答

0

你應該http://github.com/erans/twitter-csharp-library

這個片斷是從github上twitter.cs文件取來看看。

/// <summary> 
    /// Executes an HTTP POST command and retrives the information.  
    /// This function will automatically include a "source" parameter if the "Source" property is set. 
    /// </summary> 
    /// <param name="url">The URL to perform the POST operation</param> 
    /// <param name="userName">The username to use with the request</param> 
    /// <param name="password">The password to use with the request</param> 
    /// <param name="data">The data to post</param> 
    /// <returns>The response of the request, or null if we got 404 or nothing.</returns> 
    protected string ExecutePostCommand(string url, string userName, string password, string data) { 
     System.Net.ServicePointManager.Expect100Continue = false; 

     WebRequest request = WebRequest.Create(url); 
     if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { 
      request.Credentials = new NetworkCredential(userName, password); 
      request.ContentType = "application/x-www-form-urlencoded"; 
      request.Method = "POST"; 

      if (!string.IsNullOrEmpty(TwitterClient)) { 
       request.Headers.Add("X-Twitter-Client", TwitterClient); 
      } 

      if (!string.IsNullOrEmpty(TwitterClientVersion)) { 
       request.Headers.Add("X-Twitter-Version", TwitterClientVersion); 
      } 

      if (!string.IsNullOrEmpty(TwitterClientUrl)) { 
       request.Headers.Add("X-Twitter-URL", TwitterClientUrl); 
      } 


      if (!string.IsNullOrEmpty(Source)) { 
       data += "&source=" + HttpUtility.UrlEncode(Source); 
      } 

      byte[] bytes = Encoding.UTF8.GetBytes(data); 

      request.ContentLength = bytes.Length; 
      using (Stream requestStream = request.GetRequestStream()) { 
       requestStream.Write(bytes, 0, bytes.Length); 

       using (WebResponse response = request.GetResponse()) { 
        using (StreamReader reader = new StreamReader(response.GetResponseStream())) { 
         return reader.ReadToEnd(); 
        } 
       } 
      } 
     } 

     return null; 
    }