我的webrequests一直回复错误的响应为什么?

时间:2017-12-18 09:14:37

标签: c# proxy httpwebrequest webrequest httpwebresponse

所以我尝试连接到http://cmyip.org,因为内容包含有关您要连接的代理的信息。这是完美的,因为我正在学习如何使用代理进行Web请求,因此它会告诉我实际上是否与代理连接。

然而,我没有获取网站的内容,而是要求我获取代理html的内容

Before start thread
<html><head><title>Wowza Streaming Engine 4 Subscription Edition 4.7.2.01 build2
1094</title></head><body>Wowza Streaming Engine 4 Subscription Edition 4.7.2.01
build21094</body></html>
Working.

为什么显示代理的内容而不是cmyip.org?我确定我太接近代码才能看到它,但可以真正使用一些帮助。 如果您尝试在Web浏览器上连接到192.99.46.182:1935,您将看到同样的事情。

public static bool TestProxy(string proxyIP, int proxyPort)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.cmyip.org/");
            WebProxy myproxy = new WebProxy(proxyIP, proxyPort);
            myproxy.BypassProxyOnLocal = false;
            request.Proxy = myproxy;
            request.Method = "GET";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36";
            request.Timeout = 2000;

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string Content = sr.ReadToEnd();
                    console.WriteLine(Content);
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        private static void SimpleTest()
        {
            var aBool = TestProxy("192.99.46.182", 1935);
            if (aBool == true)
            {
                Console.WriteLine("Working.");
            }
            Console.ReadLine();
        }

0 个答案:

没有答案