API调用中的HttpRequestException,具体取决于用户

时间:2018-02-26 00:18:02

标签: c# .net sockets dropbox dropbox-api

我一直在讨论这个问题,我希望有人能够更好地解析错误信息,这可能会指向正确的方向。

我有一个使用Dropbox API的.NET控制台应用程序。受影响的代码段打印在下方。当我从我的计算机运行可执行文件(在与Dropbox DLL共存的文件夹中)时,它可以正常连接并按预期执行一些查找。当同一网络上的另一个用户在其计算机上运行它(类似设置)时,将在20秒后(一致地)记录下面打印的HttpRequestException。此外,如果我将其作为测试服务包装并在第三台计算机上运行,​​它会在我的帐户user / pass下按预期运行,但在另一个用户/ pass下运行时会记录相同的错误。

任何有更好的眼睛解析错误信息的人都可以帮助引导我走向解决方案吗?或者是否有人对我可能缺少的东西有所了解?我很感激任何帮助,甚至在黑暗中拍摄。

    var _AccessToken = [value]
    //DropboxCertHelper.InitializeCertPinning();
    var httpClient = new HttpClient(new WebRequestHandler { ReadWriteTimeout = 10000 })
    {
        Timeout = TimeSpan.FromMinutes(20)
    };

    try
    {
        var config = new DropboxClientConfig("MyApplication")
        {
            HttpClient = httpClient
        };

        var client = new DropboxClient(_AccessToken, config);
        ListFolderResult listing = new ListFolderResult();
        listing = await client.Files.ListFolderAsync(_AppPath, true);

        foreach (var item in listing.Entries.Where(i => i.IsFolder))
        {
            Log(item.PathDisplay);
        }
    }
    catch (Exception e)
    {
        Log(e);
    }

这是记录的错误:

System.Net.Http.HttpRequestException: An error occurred while sending the request. 
    ---> System.Net.WebException: Unable to connect to the remote server 
    ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 162.125.7.7:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Dropbox.Api.DropboxRequestHandler.<RequestJsonString>d__2f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Dropbox.Api.DropboxRequestHandler.<RequestJsonStringWithRetry>d__1a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Dropbox.Api.DropboxRequestHandler.<Dropbox.Api.Stone.ITransport.SendRpcRequestAsync>d__5`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyApplication.Program.<MyMethod>d__6.MoveNext()

0 个答案:

没有答案