0

I am beginner. Take it easy on me.
I want to set or connect proxy on that piece of code

            var requestMsg = new HttpRequestMessage(GetHttpMethod(method), url);

            if (method != APIMethod.GET)
            {
                var serializedContent = JsonConvert.SerializeObject(request);
                requestMsg.Content = new StringContent(serializedContent, Encoding.UTF8, "application/json");
            }

            WebProxy myproxy = new WebProxy("xxx.xx.xx.xx", 8080);
            requestMsg.Proxy = myproxy; <------ error


            HttpResponseMessage task = await httpClientFactory.CreateClient().SendAsync(requestMsg);

please help me set proxy hard code i read these but i cant understand
Proxy with HTTP Requests
C# Connecting Through Proxy

1 Answers1

0

You can try to use HttpClient.DefaultProxy to set the global Http proxy.

HttpClient.DefaultProxy = new WebProxy("xxx.xx.xx.xx", 8080);
Yiyi You
  • 16,875
  • 1
  • 10
  • 22