RestSharp 在 .NET Core 2.0 中不使用代理(Fiddler)

RestSharp not using Proxy (Fiddler) in .NET Core 2.0

我有一个 .NET Core 2.0 控制台 应用程序,我想用 Fiddler 或更准确地说,调试它RESTRestSharp 发出的请求。

似乎 RestSharp 没有采用我的代理设置,无论是系统代理还是显式设置的代理。

RestSharp 版本:106.2.2(撰写本文时最新版本)

static void Main(string[] args)
{
    var proxy = new WebProxy("some_non_existing_server", 8888) {BypassProxyOnLocal = false};
    var restSharpClient = new RestClient("http://www.google.ch");
    restSharpClient.Proxy = proxy;
    var request = new RestRequest("/", Method.GET);
    var result = restSharpClient.Execute(request);

    if (!result.IsSuccessful ||
        result.StatusCode != HttpStatusCode.OK ||
        result.ErrorException != null)
    {
        throw new Exception("Unexpected response.");
    }

    Console.WriteLine("Request successful.");
}

预期结果:Exception(因为代理服务器不存在)

实际结果:Request successful

我可以看到其他人对此也有困难,但通常解决方案涉及像我在上面的代码中那样显式设置代理。

有任何关于让它工作的指示吗?

(如果重要,我将在 Windows 10 x64 和 dotnet.exe <dll name> 上执行此操作)

λ dotnet --info                                                  
.NET Command Line Tools (2.1.105)                                

Product Information:                                             
 Version:            2.1.105                                     
 Commit SHA-1 hash:  141cc8d976                                  

Runtime Environment:                                             
 OS Name:     Windows                                            
 OS Version:  10.0.17134                                         
 OS Platform: Windows                                            
 RID:         win10-x64                                          
 Base Path:   C:\Program Files\dotnet\sdk.1.105\               

Microsoft .NET Core Shared Framework Host                        

  Version  : 2.0.7                                               
  Build    : 2d61d0b043915bc948ebf98836fefe9ba942be11    

原来这是一个错误,我已经用 Pull request.

修复了上游

它已经合并了,我猜它会在 106.2.2 之后包含在 RestSharp 的版本中。因此,如果它尚未发布到 NuGet,要么自己从 GitHub 编译它,要么使用晚于 106.2.2

的 NuGet 版本