How to use http post with proxy support in c#

后端 未结 3 1017
面向向阳花
面向向阳花 2020-12-28 21:39

How to use http post with proxy support in c# and multipart form data upload method

相关标签:
3条回答
  • 2020-12-28 22:26

    If you need to configue a proxy then you can do so in the .config file:-

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

    See this question on form data posting.

    0 讨论(0)
  • 2020-12-28 22:32

    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.

    You can mention the proxy settings either in web.config or in code.

    <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";
    
    0 讨论(0)
  • 2020-12-28 22:33

    This post by Brian Grinstead explains how you can do just that.

    For proxy support, you only need to pass a Proxy setting to 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);
    
    0 讨论(0)
提交回复
热议问题