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 に答える