2009-09-03 57 views

回答

16

This post by Brian Grinstead解釋瞭如何做到這一點。

對於代理支持,您只需將Proxy設置設置爲HttpWebRequest即可。所以,在上面的例子中,你會改變:

HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest; 

要:

string MyProxyHostString = "192.168.1.200"; 
int MyProxyPort = 8080; 

HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest; 
request.Proxy = new WebProxy (MyProxyHostString, MyProxyPort); 
+0

非常好的解決方案,謝謝 –

+0

這種方法的問題是它難以將代理地址/端口編碼到編譯代碼中。 – AnthonyWJones

+6

這可以很容易地放置在其他地方。我用這種方式來更好地解釋這個例子。 – Druid

2

代理支持如果您需要configue一個代理,那麼你可以在config文件這樣做: -

<system.net> 
    <defaultProxy enabled="true"> 
    <proxy proxyaddress="http://myproxyserver:8080" bypassonlocal="True"/> 
    </defaultProxy> 
</system.net> 

在表格數據發佈上看到這個question

+0

HTTP POST? webRequest? 你說什麼? –

+0

對不起,我們只是詢問代理支持,但問題的最大部分是關於多部分表單數據。 – AnthonyWJones

+0

我可以在一些前端使用代理嗎? http://www.proxy4free.com/page1.html to http post 189.80.133.186 \t 8080 ?? –

0

如果Web請求與默認代理 本地主機正常工作,而不是在你的Web服務器的工作,那麼你必須設置您的 公司批准的代理服務器,並將您在Web服務器中從Web應用程序連接至 的URL列入白名單。

您可以在web.config或代碼中提及代理設置。

<system.net> 
    <defaultProxy enabled="true"> 
    <proxy proxyaddress="http://yourcompanyproxyserver:8080" bypassonlocal="True"/> 
    </defaultProxy> 
</system.net> 

(或)

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("URL"); 
wr.Proxy = new WebProxy("companyProxy",Portnumber); 
wr.Method = "POST";