简体   繁体   English

在.NET Core 2.0中RestSharp不使用代理(提琴手)

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

I've got a .NET Core 2.0 Console application that I would like to debug with Fiddler , or more precise, the REST request made by RestSharp . 我有一个.NET Core 2.0控制台应用程序,我想用Fiddler或更准确地说是RestSharp发出的REST请求进行调试

It seems that RestSharp does not take my proxy settings, no matter if it's the system proxy, or a proxy explicitly set. 似乎RestSharp不会采用我的代理设置,无论是系统代理还是显式设置的代理。

RestSharp version: 106.2.2 (latest as of this writing) 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.");
}

Expected result: Exception (because proxy server does not exist) 预期结果: Exception (因为代理服务器不存在)

Actual result: Request successful 实际结果: Request successful

I can see others having difficulties with this as well, but usually the solution involved setting the proxy explicitly like I do in the code above. 我可以看到其他人对此也有困难,但是通常解决方案包括像上面的代码中那样显式设置代理。

Any pointers on getting this to work? 关于使它起作用的任何指示?

(if it matters, I'm executing this on Windows 10 x64 with dotnet.exe <dll name> ) (如果有关系,我将在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\2.1.105\               

Microsoft .NET Core Shared Framework Host                        

  Version  : 2.0.7                                               
  Build    : 2d61d0b043915bc948ebf98836fefe9ba942be11    

Turns out this was a bug, which I have fixed upstream with a Pull request . 原来这是一个错误,我已经通过Pull请求在上游修复了该错误。

It is already merged and I guess it will be included in versions of RestSharp after 106.2.2 . 它已经合并,我想这将被列入后RestSharp版本106.2.2 So either compile it yourself from GitHub if it is not yet released to NuGet, or use a NuGet version later than 106.2.2 因此,如果尚未发布到NuGet,请从GitHub自己编译,或者使用106.2.2之后的NuGet版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM