受欢迎的博客标签

Is there a way to use an HTTPS proxy in .NET 6

Published

I need to check if certain HTTPS proxies are working。

somebody has used the following code to use the HTTPS proxy successfully

 

var proxy = new WebProxy
            {
                Address = new Uri($"https://proxy-server:port"),
                BypassProxyOnLocal = false,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(
        userName: "user",
        password: "Pass")
            };

            // Create a client handler that uses the proxy
            var httpClientHandler = new HttpClientHandler
            {
                Proxy = proxy,
            };

            // Disable SSL verification
            httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

            // Finally, create the HTTP client object
            var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);

            var result = await client.GetStringAsync("path");
            Console.WriteLine(result);

 

come from:https://learn.microsoft.com/en-us/answers/questions/1181349/is-there-a-way-to-use-an-https-proxy-in-net-6