add proxy to httpclient c#

public static async Task<string> Http1_Get_With_Proxy(string url1)
{
    string html_content = "";
    try
    {
    WebProxy proxy = new WebProxy
    {
    Address = new Uri($"http://1.2.3.4:8888"),
    };
    ServicePointManager.Expect100Continue = false;
    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    HttpClientHandler clientHandler = new HttpClientHandler()
    {
    AllowAutoRedirect = true,
    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
    Proxy = proxy,
    };
    using HttpClient client1 = new HttpClient(clientHandler);
    client1.DefaultRequestHeaders.Accept.Clear();
    client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
    client1.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url1);
    HttpResponseMessage response = await client1.SendAsync(request);
    if (response.StatusCode == HttpStatusCode.OK)
    {
    html_content = await response.Content.ReadAsStringAsync();
    }
    }
    catch (HttpRequestException ex)
    {
    Console.WriteLine(ex.Message);
    }
    return (html_content);
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
add proxy to webclient c# c# webclient set proxy set WebClient.Proxy httpclient proxy credentials c# c# use proxy with webclient c# set proxy for restclient c# set proxy for httpclient c# http request through proxy proxy httprequest c# c# http proxy injector c# http proxy server how to use http proxy in C# how to set proxy for httpclient httpclient set proxy c# .net httpclient proxy request proxy c# http client using proxy c# c# http client proxy tutorial c# httpclient using proxy set proxy webrequest c# webclient proxy c# http request c# with proxy using proxy with smtpclient c# C# proxy HTTP request How to add a proxy httprequest c# https proxy httpclient httpclient with proxy httpclient use proxy proxy http C# connect http proxy C# httpclient http proxy proxy http httpclient C# .net httpclient set proxy c# httpclient proxy httpClient class use proxy c# httpClient use proxy c# proxy for httpclient C# httpclient with proxy c# asp httpclient set proxy httpclient postAsync proxy httpclient proxt Titanium Web Proxy get http headers C# https proxy for httpclient C# set httpclient proxy c# HttpClient proxy .net core httpclient proxy how to use proxy with authentication c# windows proxy httpclient proxy c# httpclient use proxy HttpClient add proxy c# HttpClient add proxy proxys with http.client C# how to apply a proxy to httpclient c# http proxy client c# httpclient using proxy http httpclient disable proxy c# httpclient handler proxy c# httpclient set proxy credentials c# httpclient proxy credentials c# httpclient use system proxy add proxy to httpclient c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source