2009-09-03 39 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";