简体   繁体   English

如何在c#中使用带有代理支持的http帖子

[英]How to use http post with proxy support in c#

如何在c#和多部分表单数据上传方法中使用带有代理支持的http post

This post by Brian Grinstead explains how you can do just that. Brian Grinstead的这篇文章解释了你如何才能做到这一点。

For proxy support, you only need to pass a Proxy setting to HttpWebRequest . 对于代理支持,您只需将Proxy设置传递给HttpWebRequest So, in the above example, you would change: 因此,在上面的示例中,您将更改:

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

To: 至:

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

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

If you need to configue a proxy then you can do so in the .config file:- 如果您需要配置代理,那么您可以在.config文件中执行此操作: -

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

See this question on form data posting. 在表单数据发布上查看此问题

If the web request works fine in your localhost with default proxy and not working in your web server, then you have to set your company's approved proxy and also whitelist the URL you are connecting to from your web application in the web server. 如果Web请求在您的localhost中使用默认代理并且无法在您的Web服务器中正常工作,那么您必须设置公司的已批准代理,并且还要从Web服务器中的Web应用程序将您要连接的URL列入白名单。

You can mention the proxy settings either in web.config or in code. 您可以在web.config或代码中提及代理设置。

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

(or) (要么)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM