5

我正在尝试使用公共代理服务器 (http://www.unblockwebnow.info/) 将 HTTP 请求发送到目标站点,例如http://stackoverflow.com :)

我的 HTTP 客户端具有以下架构:

string url = "http://stackoverflow.com";
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.Method = "GET";

WebProxy myProxy = new WebProxy();
myProxy.Address = new Uri("http://www.unblockwebnow.info/");
HttpWRequest.Proxy = myProxy;

HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), encoding);
var rawHTML = sr.ReadToEnd();
sr.Close();

执行 rawHTML 的代码后,我得到"pageok -managed by puppet - hostingcms02 pageok"

如果我注释掉HttpWRequest.Proxy = myProxy;行,我会得到网站内容。

4

1 回答 1

5

这似乎有效,但不适用于您的代理(不知道 unblockwebnow.info 的端口号)。在 URI 中的“:”后添加端口号

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://stackoverflow.com";
            HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWRequest.Method = "GET";

            WebProxy myProxy = new WebProxy();

            //United States proxy, from http://www.hidemyass.com/proxy-list/
            myProxy.Address = new Uri("http://72.64.146.136:8080");
            HttpWRequest.Proxy = myProxy;

            HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
            StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), true);
            var rawHTML = sr.ReadToEnd();
            sr.Close();

            Console.Out.WriteLine(rawHTML);
            Console.ReadKey();
        }
    }
}
于 2012-12-19T18:39:03.917 回答