RestSharp ignores system proxies (e.g. Fiddler) on .NET Core

I want to test http traffic with Fiddler, but no http traffic was captured, my test codes are:

private static void ByRestSharp()
{
    var restClient = new RestClient("https://jsonplaceholder.typicode.com");
    var request = new RestRequest("posts", Method.GET);
    var response = restClient.Get<List<Post>>(request);
    Console.WriteLine("{0} posts return by RestSharp.", response.Data.Count);
}

But after I changed the use of HttpClient, Fiddler can capture http traffic, code samples:

private static void ByHttpClient()
{
    var httpClient = new HttpClient();
    using (var req = new HttpRequestMessage(HttpMethod.Get, "https://jsonplaceholder.typicode.com/posts"))
    using (var resp = httpClient.SendAsync(req).Result)
    {
        var json = resp.Content.ReadAsStringAsync().Result;
        var users = SimpleJson.SimpleJson.DeserializeObject<List<Post>>(json);
        Console.WriteLine("{0} posts return by HttpClient.", users.Count);
    }
}

Is this a RestSharp or Fiddler problem?

+4
source share
1 answer

RestSharp supports the system proxy until we move on to .NET Standard. Then we had problems with the proxy server on .NET Core, and then the use of the system proxy was completely removed. We have a problem with this problem .

Code from the problem, confirmed as working:

var client = new RestClient("http://www.google.com");
client.Proxy = new WebProxy("127.0.0.1", 8888);
var req = new RestRequest("/", Method.GET);
var resp = client.Execute(req);
+6
source

Source: https://habr.com/ru/post/1689605/


All Articles