0

This is the code that I wrote.

        NameValueCollection values = new NameValueCollection();
        values.Add("ctl00$ContentPlaceHolder1$ctrl9$txtDate1", "01.01.2012");
        values.Add("ctl00$ContentPlaceHolder1$ctrl9$txtDate2", "26.11.2012");
        values.Add("ctl00$ContentPlaceHolder1$ctrl9$cmbSymbol", "DHP");

        using (WebClient client = new WebClient())
        {
            client.Headers.Add("ContentType","application/x-www-form-urlencoded");
            client.Headers.Add("Cookie","ASP.NET_SessionId");
            client.Headers.Add("userAgent","Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.16");
            client.Headers.Add("Host","www.mse.mk");
            client.Headers.Add("Accept","text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1");
            client.Headers.Add("KeepAlive","true");
            byte[] result = client.UploadValues("Some Url", "POST", values);
        }

But when I run this code I get the exception "Too many automatic redirections were attempted". So my question is where is the error and how to fix it.

Thanks

Eko Luks
  • 1
  • 1
  • 1
  • If you need a cookie you have to provide one. Can you use [fiddler](http://www.fiddler2.com) to see what http request are made? – rene Jul 19 '13 at 15:35
  • possible duplicate of ["too many automatic redirections were attempted" error message when using a httpWebRequest in .NET](http://stackoverflow.com/questions/518181/too-many-automatic-redirections-were-attempted-error-message-when-using-a-http) – Jim Mischel Jul 19 '13 at 15:56
  • @JimMischel it's WebClient Against HttpwebRequest that makes it much different. – confusedMind Sep 01 '13 at 20:38
  • @confusedMind: You're right. Here's a better reference: http://stackoverflow.com/q/1777221/56778 – Jim Mischel Sep 01 '13 at 20:54

0 Answers0