(400) Bad request - HttpRequest with proxy

Viewed 142

I'm trying to GET string from website with HttpRequest. It works fine, but when I want to implement proxy then it always returns 400 Bad Request. Proxy works because I can get response from www.google.com when using it. But other websites I tried doesn't work.

For security reasons I can't share here my API but it looks something like this -> https://mywebsite.com/api/email-details?email=email@gmail.com And this link show you result string that I want to get in my application. I can get without proxy, proxy is free from internet (maybe that can be problem because web blocked it or something?)

My code

            var url = "https://mywebsite.com/api/email-details?email=email@gmail.com";
            var httpRequest = (HttpWebRequest)WebRequest.Create(url);
            httpRequest.Proxy =  new WebProxy
            {
                Address = new Uri($"http://199.19.226.12:80"),
            };

            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }

Thank you very much for all answers, I tried to figure out for so long. Have a great day :)

0 Answers
Related