Bhavesh Ghul

Bhavesh Ghul

  • 820
  • 1k
  • 54.5k

too many automatic redirections were attempted webclient c#

Oct 9 2019 10:11 AM
Hello anyone can you, please help below error...?
  1. public void Index()  
  2.         {  
  3.             string URI = "www.url.com/addform";  
  4.             try  
  5.             {  
  6.                 using (WebClient wc = new WebClient())  
  7.                 {  
  8.                     wc.Headers[HttpRequestHeader.ContentType] = "multipart/form-data";  
  9.                     wc.Headers["Host"] = "www.url.com";  
  10.                     wc.Headers["X-CSRF-TOKEN"] = "df7641fe-1168-4952-a203-fa96909db251";  
  11.                     wc.Headers["X-Requested-With"] = "XMLHttpRequest";  
  12.                     wc.Headers.Add(HttpRequestHeader.Cookie, "JSESSIONID=6CDB5B4F952F0A996E0C035288771CE7; path=/; domain=.www.url.com;");  
  13.   
  14.                     GWModel oGWModel = new GWModel();  
  15.                     oGWModel.refStateId = "10";  
  16.                     oGWModel.refDistrictId = "74";  
  17.                     oGWModel.refBlockTehsilId = "4328";  
  18.                     oGWModel.refVillageId = "281394";  
  19.                     oGWModel.enumerationDate = "28/09/2019";  
  20.                     var data = new JavaScriptSerializer().Serialize(oGWModel);  
  21.                     string HtmlResult = wc.UploadString(URI,"POST", data);  
  22.                 }  
  23.             }  
  24.             catch (Exception ex)  
  25.             {  
  26.                 throw;  
  27.             }  
  28.         }  
Exception Throw - too many automatic redirections were attempted.
 
Thanks & Regards
Bhavesh 

Answers (2)