Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
webscraping project i get error when updating data through code scraped site page to webclient post

C#
string fromdate = string.Format("{0:yyyy-MM-dd}", DateTime.Parse(FromDate, new CultureInfo("hi-IN")));
            string todate = string.Format("{0:yyyy-MM-dd}", DateTime.Parse(ToDate, new CultureInfo("hi-IN")));
            string Cthotelencoding = Uri.EscapeUriString(RoomTypeName).Replace("%20", "+").Replace("/", "%2F");
            string sessioncookie = "login=true;" + cookiestring;
            string[] crsf = cookiestring.Split('=', ';');
            var postdata = "csrfmiddlewaretoken=" + crsf[1] + "&roomtypecode=%7B%22roomtypecode%22%3A%22" + RoomTypeCode + "%22%2C%22roomtypename%22%3A%22" + Cthotelencoding + "%22%7D&fromDate=" + fromdate + "&toDate=" + todate + "&checkall=" + DaysList + "inventory_action=default_inventory&available=16&minnonights=&cutoff_filter=hours&cutoff=";
            

            string responseJson = string.Empty;
            using (WebClient client = new WebClient())
            {
                client.Headers[HttpRequestHeader.Accept] = "*/*";
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded; charset=UTF-8";
                client.Headers[HttpRequestHeader.ContentLength] = (postdata.Length).ToString();
                client.Headers[HttpRequestHeader.Cookie] = sessioncookie;
                client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
                byte[] response = client.UploadData("https://in.****.com/extranet/inventory/submitroominventory/", Encoding.UTF8.GetBytes(postdata));//======>(ERROR SPOT)
                responseJson = Encoding.UTF8.GetString(response);
            }
Posted
Updated 13-Nov-15 1:24am
v2
Comments
ZurdoDev 13-Nov-15 7:30am    
And the error is....?
Member 11264533 13-Nov-15 7:46am    
when i post data to update that site some data then i get error is An exception occurred during a WebClient request.
ZurdoDev 13-Nov-15 7:49am    
We need to know the rest of the error. There should be something more specific.
Member 11264533 13-Nov-15 7:54am    
i Understand that But where and what i need to do
ZurdoDev 13-Nov-15 8:01am    
The exception should have more of an error. We need to see that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900