views:

520

answers:

2

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

+1  A: 

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.

AnthonyWJones
http post?webRequest ?what atr you saying?
monkey_boys
Sorry thought you we just asking about proxy support, however the largest part of the question is regarding multipart form data.
AnthonyWJones
can i use proxy in some one ex. http://www.proxy4free.com/page1.htmlto http post 189.80.133.186 8080 ??
monkey_boys
Don't see why not, assuming you really want to expose your data to any Tom, Dick or Harry that might be running a free proxy server.
AnthonyWJones
proxy support ?
monkey_boys
"Proxy support ?" What exactly are you asking? The answer describes how you specify a proxy server that classes in System.Net namespace will use.
AnthonyWJones
+1  A: 

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);
Druid
very good solution thanks
monkey_boys
The problem with this approach is it hard codes the proxy address/port into the compiled code.
AnthonyWJones
That can easily be placed anywhere else. I put it in this way to explain the example better.
Druid