9

我们的控制台应用程序每分钟向 Facebook 发出数百个 WebRequest(使用多个应用程序和数百个访问令牌)。现在,他们开始失败,标题中出现异常消息(“请求被中止:请求被取消”)。我们在互联网上搜索了几个小时,并尝试了所有可能的解决方案,但没有任何帮助。

这些没有帮助:

webRequest.Timeout = 20000; //A request that didn't get respond within 20 seconds is unacceptable, and we would rather just retry.
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.ServicePoint.Expect100Continue = false;

有人有其他想法吗?

编辑:

异常的ToString:System.Net.WebException:请求被中止:请求被取消。---> System.Net.WebException:在 System.Net.HttpWebRequest.FindServicePoint(Boolean forceFind) 的 System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy, ProxyChain& chain, HttpAbortDelegate& abortDelegate, Int32& abortState) 处取消了请求在 System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception) 在 System.Net.HttpWebRequest.SetResponse(Exception E) --- 内部异常堆栈跟踪结束 --- 在 System.Net.HttpWebRequest.GetResponse() 在 WebException 消息:请求被中止:请求被取消。

编辑2:我们没有达到极限。我们知道什么时候会发生这种情况,问题不是那样。我们已经这样做了两年,而这件事在整个过程中只发生过两次。每个 AccessToken 我们只执行 2-3 个请求/分钟,而 Facebook 上的限制是 600 个请求/accesstoken/ip。

编辑3:我想为有此或类似问题的人添加一个额外的提示:确保您处理您的 RequestStream、您的 Response 和您的 ResponseStream 对象。

4

2 回答 2

10

http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/ServicePointManager@cs/1305376/服务点管理器@cs

我可以看到抛出异常的位置。您是否尝试增加 HTTP 请求限制?默认值为每秒 2 次。

ServicePointManager.DefaultConnectionLimit = 1000;
于 2014-02-04T10:31:14.853 回答
0
 My Solve for Xamarin

   public async Task<string> GetMessageEx(HttpWebResponse response)
    {
        Stream streamResponse = response.GetResponseStream();
        StreamReader streamRead = new StreamReader(streamResponse);
        string result = await streamRead.ReadToEndAsync();
        await streamResponse.FlushAsync();
        return result;
    }
于 2022-01-05T07:30:06.523 回答