2

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.

It seems that RestSharp does not take my proxy settings, no matter if it's the system proxy, or a proxy explicitly set.

RestSharp version: 106.2.2 (latest as of this writing)

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)

Actual result: 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>)

λ 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    
johnny 5
  • 19,893
  • 50
  • 121
  • 195
MichelZ
  • 4,214
  • 5
  • 30
  • 35
  • 2
    Possible duplicate of [RestSharp ignoring system proxy (for example Fiddler) on .NET Core](https://stackoverflow.com/questions/47408423/restsharp-ignoring-system-proxy-for-example-fiddler-on-net-core) – Koby Douek May 07 '18 at 08:37
  • @KobyDouek thanks, the "solution" on the duplicate question is exactly what I use in my question, hence my question :) – MichelZ May 07 '18 at 08:38
  • I've got the exact same problem today! This weird timing is making me think it's related to 1803. Are you on Windows 10 and have you updated it? – Luis Ferrao May 07 '18 at 10:42
  • @LuisFerrao indeed, I am and I have updated... I've even started debugging RestSharp now :) However "plain old webrequest" does seem to work fine, at least on .NET 4.7.1. (Trying to take .NET Core out of the equation for now) – MichelZ May 07 '18 at 12:44
  • 2
    @LuisFerrao I have made a PR to RestSharp now, I think it's a bug in their code. https://github.com/restsharp/RestSharp/pull/1118 – MichelZ May 07 '18 at 16:02

1 Answers1

0

Turns out this was a bug, which I have fixed upstream with a Pull request.

It is already merged and I guess it will be included in versions of RestSharp after 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

MichelZ
  • 4,214
  • 5
  • 30
  • 35