0

I am relatively new to C# especially in the web aspects of it.

Let's say I have the following:

string URI = "http://www.domain.com/post.php";
string params = "param1=value1&param2=value2&param3=value3";

I understand I can post data like this:

using (WebClient wc = new WebClient())
{
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    string HtmlResult = wc.UploadString(URI, params);
}

But how do I use a proxy when posting this data?

I found this Related Link:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
WebProxy myproxy = new WebProxy("1.1.1.1", 80);
myproxy.BypassProxyOnLocal = false;
request.Proxy = myproxy;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Community
  • 1
  • 1
Joey Hipolito
  • 3,108
  • 11
  • 44
  • 83

1 Answers1

1

WebClient.Proxy is the property you are looking for:

WebProxy[] myproxies = new WebProxy[] { new WebProxy("1.1.1.1", 80), 
     new WebProxy("1.1.1.2", 80) };
var currentProxy = 0;

while (true)
{
   // set proxy to new one every iteration...
   currentProxy = (currentProxy + 1) % myproxies.Length;
   using (WebClient wc = new WebClient())
   {
     wc.Proxy = myproxies[currentProxy]; 
     wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
     string HtmlResult = wc.UploadString(URI, params);
   }
}
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179