2016-01-22 50 views
1

我們從Twitter的時間表將最新的微博,但我看到一個錯誤「不支持的證書密鑰算法」。並提示「底層連接已關閉:接收方發生意外錯誤」。這隻發生在舞臺和現場服務器上,不在我的開發機器上。證書密鑰算法沒有與Twitter的API支持

頁面返回一個標準的服務器錯誤。下面是我們用screenname調用的類。我們再次檢查了oAuth消費者密鑰並且祕密也是正確的。在WebResponse authResponse = authRequest.GetResponse();發生

public static List<Tweet> GetTimeline(string screenName) 
{ 
    try 
    { 
     // Do the Authenticate 
     var authHeaderFormat = "Basic {0}"; 
     var authHeader = string.Format(authHeaderFormat, 
              Convert.ToBase64String(Encoding.UTF8.GetBytes(Uri.EscapeDataString(oAuthConsumerKey) + ":" + Uri.EscapeDataString((oAuthConsumerSecret))) 

               )); 
     var postBody = "grant_type=client_credentials"; 
     HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(oAuthUrl); 

     authRequest.Headers.Add("Authorization", authHeader); 
     authRequest.Method = "POST"; 
     authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; 
     authRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; 
     using (Stream stream = authRequest.GetRequestStream()) 
     { 
      byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody); 
      stream.Write(content, 0, content.Length); 
     } 
     authRequest.Headers.Add("Accept-Encoding", "gzip"); 
     WebResponse authResponse = authRequest.GetResponse(); 
     // deserialize into an object 
     TwitAuthenticateResponse twitAuthResponse; 
     using (authResponse) 
     { 
      using (var reader = new StreamReader(authResponse.GetResponseStream())) 
      { 
       JavaScriptSerializer js = new JavaScriptSerializer(); 
       var objectText = reader.ReadToEnd(); 
       twitAuthResponse = JsonConvert.DeserializeObject<TwitAuthenticateResponse>(objectText); 
      } 
     } 

     // Do the timeline 
     var timelineFormat = 
       "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={0}&include_rts=1&exclude_replies=1&count=20"; 
     var timelineUrl = string.Format(timelineFormat, screenName); 
     HttpWebRequest timeLineRequest = (HttpWebRequest)WebRequest.Create(timelineUrl); 
     var timelineHeaderFormat = "{0} {1}"; 
     timeLineRequest.Headers.Add("Authorization", string.Format(timelineHeaderFormat, twitAuthResponse.token_type, twitAuthResponse.access_token)); 
     timeLineRequest.Method = "Get"; 
     WebResponse timeLineResponse = timeLineRequest.GetResponse(); 

     var timeLineJson = string.Empty; 
     using (authResponse) 
     { 
      using (var reader = new StreamReader(timeLineResponse.GetResponseStream())) 
      { 
       timeLineJson = reader.ReadToEnd(); 
      } 
     } 

     JArray tweets = JArray.Parse(timeLineJson); 

     return (from t in tweets 
      select new Tweet 
      { 
       date = DateTime.ParseExact((string)t["created_at"], "ddd MMM dd HH:mm:ss +ffff yyyy", new System.Globalization.CultureInfo("en-US")), 
       link = t["entities"]["urls"].Count() > 0 ? (string)t["entities"]["urls"][0]["url"] : "", 
       tweet = LinkUpTweet((string)t["text"]), 
       author = (string)t["user"]["name"], 
       screenname = (string)t["user"]["screen_name"], 
       tweetLink = string.Format(@"https://twitter.com/{0}/status/{1}", screenName, (string)t["id_str"]) 
      }).ToList(); 
    } 
    catch (Exception ex) 
    { 
     // Send Email Error 
     return new List<Tweet>(); 
    } 

的錯誤,但我不知道如何解決這個問題。

加入以下的web.config對結果

<system.diagnostics> 
    <switches> 
     <add name="System.Net" value="0"/> 
    </switches> 
</system.diagnostics> 

這裏有什麼建議沒有關係?

謝謝!

+0

簡單的問題:你是否嘗試過訪問您發佈的URL在您的分期和PROD服務器主機的web瀏覽器?我問,因爲您的問題聽起來像是低級證書握手錯誤,而不是與oAuth/Basic Auth握手有關。 – toadflakz

+0

這篇文章建議system.diagnotics部分可能會導致此問題 http://stackoverflow.com/questions/30576179/what-c​​ould-cause-the-certificate-key-algorithm-is-not-supported-exception-on -a –

+0

我檢查了服務器,只是看到一個通用的內部服務器錯誤。我也沒有在我的web.config中添加system.diagnostics部分,並沒有什麼不同。我也讀過那篇文章,但沒有喜樂。 –

回答

1

你檢查過一次,是失敗的服務器上?如果服務器時間與Twitter服務器上的時間相差幾分鐘,您有時可以看到請求失敗。確保所有內容都與NTP同步並查看是否有效。

0

我們固定它 - 我不認爲我們會找到什麼原因引起的,但我們完成了消滅被編譯,對於解決方案,並在服務器上的一個新的文件夾重建,它的工作DLL的。我想項目中某處的一行代碼正在破壞它,但不知道什麼是不幸的。

我們做檢查的時間在服務器上,但一切似乎是確定存在。

相關問題