【问题标题】:Twitterizer the underlying connection was closedTwitterizer 底层连接已关闭
【发布时间】:2012-11-26 12:30:51
【问题描述】:

我使用 twitterizer 进行推文和关注,但在文件 TwitterCommand.cs 中,在线

responseData = ConversionUtility.ReadStream(exceptionResponse.GetResponseStream());

我得到一个异常:底层连接已关闭:服务器关闭了预期保持活动状态的连接。

exceptionResponse 为 null,所以上面的代码看起来像抛出异常:

// The exception response should always be an HttpWebResponse, but we check for good measure.
HttpWebResponse exceptionResponse = wex.Response as HttpWebResponse;

if (exceptionResponse == null)
{
    throw;
}

不明白为什么会这样=\

Uri,代码为:http://api.twitter.com/1/statuses/update.json,所以在更新状态(推文)时会出现异常。

为了更新我使用这个代码:

TwitterStatusAsync.Update(token, tweet, null, TimeSpan.FromSeconds(0), (resp) =>
        {
            TwitterAsyncResponse<TwitterStatus> response = resp;
            if (response.Result != RequestResult.Success)
            {
                this._twtLogger.addLine(String.Format("{0}: error when get response from server", account.title));
                this._twtLogger.addLine(String.Format("{0}: {1}", account.title, response.ErrorMessage));
                return;
            }

            this._twtLogger.addLine(String.Format("{0}> {1}: Tweeted ok!", response.ResponseObject.CreatedDate, account.title));
        });

添加:

System.Net.WebException was unhandled by user code
  Message=The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
  Source=System
  StackTrace:
       at System.Net.HttpWebRequest.GetResponse()
       at Twitterizer.WebRequestBuilder.ExecuteRequest()
       at Twitterizer.Core.TwitterCommand`1.ExecuteCommand()
       at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand`1 command)
       at Twitterizer.TwitterFriendship.Create(OAuthTokens tokens, Decimal userId, CreateFriendshipOptions options)
       at Twitterizer.TwitterFriendship.Create(OAuthTokens tokens, Decimal userId)
       at Twtt2.Core.TwitterActions.twtActions.Follow(twtTwitterAccount account, QueueElement QueElement, OAuthTokens token) in C:\Users\fs\Documents\Visual Studio 2010\Projects\Twtt2\Twtt2\Core\TwitterActions\twtActions.cs:line 148
       at Twtt2.Core.TwitterActions.twtActions.Process(EQueue eq) in C:\Users\fs\Documents\Visual Studio 2010\Projects\Twtt2\Twtt2\Core\TwitterActions\twtActions.cs:line 40
       at Twtt2.Core.AppQueueProcessor.<QueueProc>b__7(EQueue eq) in C:\Users\fs\Documents\Visual Studio 2010\Projects\Twtt2\Twtt2\Core\AppQueueProcessor.cs:line 90
       at System.Threading.Tasks.Parallel.<>c__DisplayClass2d`2.<ForEachWorker>b__23(Int32 i)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
  InnerException: System.IO.IOException
       Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
       InnerException: System.Net.Sockets.SocketException
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            InnerException: 

【问题讨论】:

  • 你能发布异常的堆栈跟踪吗?

标签: c# .net twitterizer


【解决方案1】:

这似乎是连接问题。检查您的代理/防火墙设置。另外,尝试同步调用,看看它是否有效。 (我怀疑它不会,但它可能会帮助您调试问题。)

【讨论】:

  • 这发生在 30 分钟或 1 小时的漂亮推文之后。 =\
  • 无法理解如何解决这个问题 :( 同步也出现异常崩溃。
猜你喜欢
  • 1970-01-01
  • 2013-10-31
  • 2018-01-31
  • 2017-09-21
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多