C
C
CityzenUNDEAD2021-08-02 19:29:02
C++ / C#
CityzenUNDEAD, 2021-08-02 19:29:02

How to send a request to a site through a proxy address?

I'm trying to send a request to a site through a proxy like this

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://whoer.net/ru");
            var proxy = new WebProxy("190.151.107.50", 5678);

            request.Proxy = proxy;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string ping;

            using (StreamReader stream = new StreamReader(
                response.GetResponseStream(), System.Text.Encoding.UTF8))
            {
                ping = stream.ReadToEnd();
            }

            Console.WriteLine(ping);
        }


In response, I get a System.Net.WebException exception: "An error occurred while sending the request. The response ended prematurely.
If you do not use a proxy address, then the site's response comes.
What's wrong here?
I also used proxy constructor overloads in the form
var proxy = new WebProxy("190.151.107.50:5678");
var proxy = new WebProxy("190.151.107.50:5678", true);

Exception still thrown.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-08-02
@BasiC2k

Perhaps the proxy you're using doesn't support http s ?
Try another proxy. It is advisable to check it first.
Also, before creating the request, add:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
this enables https support in HttpWebRequest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question