2012-12-19 7 views
5

Tôi cố gắng để sử dụng máy chủ proxy công cộng (http://www.unblockwebnow.info/) để gửi yêu cầu HTTP đến trang web đích, nói http://stackoverflow.com :)Sử dụng máy chủ proxy công cộng trong HTTP client

client HTTP của tôi có sau kiến ​​trúc:

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(); 

sau khi thực hiện các mã cho rawHTML tôi nhận được "pageok -managed by puppet - hostingcms02 pageok"

Nếu tôi nhận xét ra HttpWRequest.Proxy = myProxy; dòng, tôi nhận được nội dung trang web.

+1

Địa chỉ proxy là tất cả các điều sai lầm. Trông giống như một trang web rác. –

+0

hãy thử một proxy khác –

+0

và cổng cũng – VladL

Trả lời

5

Điều này dường như hoạt động, nhưng không phải với proxy của bạn (không biết số cổng cho unblockwebnow.info). Số cổng đã thêm sau ":" trong 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(); 
     } 
    } 
} 
+0

Nếu nó không hoạt động với proxy của mình, thì điều này không trả lời câu hỏi của anh ta. – IronMan84