2016-01-22 48 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的。我想项目中某处的一行代码正在破坏它,但不知道什么是不幸的。

我们做检查的时间在服务器上,但一切似乎是确定存在。

相关问题