2016-05-21 99 views
-1

我試圖通過使用的WebRequest與代理服務器訪問Internet瀏覽器的在C#中的第一次,第一次訪問IEXPLORER ..通過代理使用的WebRequest錯誤

應用程序背後的想法是,你可以訪問通過IExplorer與您在文本框中輸入代理的網站(如下所示)

我試過我的方法,但它連接到網站的一秒鐘,並顯示我的正常IP(不代理一個),然後它崩潰和它給了我這個錯誤(下面)

不知道是什麼原因造成它和/或如何解決它..是在想帽子也許有經驗的人將能夠明白這比我更好,因爲它的我第一次與代理在C#

enter image description here

enter image description here

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    { 
     webBrowser1.Navigate(browserNavigationTxtBox.Text); 
     var request = (HttpWebRequest)WebRequest.Create("http://www.whatsmyip.org/"); 
     var myproxy = new WebProxy(proxyBox.Text, false); 
     request.Proxy = myproxy; 
     request.Method = "GET"; 
     var response = (HttpWebResponse)request.GetResponse(); 
    } 

    private void Start_Click(object sender, EventArgs e) 
    { 
     webBrowser1.Navigate(browserNavigationTxtBox.Text); 
    } 
} 

}

+0

每[該文檔(https://msdn.microsoft.com/en-us/library/system.net.webproxy(V = vs.110)的.aspx),你需要一個* uri *代理,而不僅僅是一個IP和端口。試試'http://180.175.16.228:8118 /'代替。 –

+0

@CharlesMager看起來應用程序只會凍結,當我嘗試或崩潰,並給出相同的錯誤,但我下一次使用代理時記住這一點,它實際上是一個非常好的提示! –

回答

1

工作雖然可以更改註冊表值以編程方式設置代理

HKCU \軟件\微軟\的Windows \ CurrentVersion \ Internet設置\訪問代理服務器 HKCU \軟件\微軟\的Windows \ CurrentVersion \ Internet設置\ ProxyOverride

我會用FiddlerCore 設置我的代理有更多的控制關於發送和接收的內容(以及能夠使用襪子代理)。

MyProxy.Start(); 
webBrowser1.Navigate(url); 

public class MyProxy 
{ 
    public static void Start() 
    { 
     Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest; 
     Fiddler.FiddlerApplication.Startup(8888, true, true); 
    } 

    static void FiddlerApplication_BeforeRequest(Fiddler.Session oSession) 
    { 
     oSession["X-OverrideGateway"] = "94.76.117.14:8080"; // <-- Your Http Proxy 
     //oSession["x-OverrideGateway"] = "socks=ip:port"; //For socks proxy 
     Console.ForegroundColor = ConsoleColor.Blue; 
     Console.WriteLine(oSession.fullUrl); 
    } 

    public static void Stop() 
    { 
     Fiddler.FiddlerApplication.Shutdown(); 
    } 
} 
+0

我不能改變oSession [「X-OverrideGateway」] =「94.76.117.14:8080」;到我的文本框的價值? –

+0

@ Alexander.Matt如何自行測試並分享結果? – Eser

+0

我做了,我的文本框沒有彈出在intellisense中 –