I want to publish data on a website. I process cookies with this code:
CookieCollection cookies = new CookieCollection();
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
I am processing the viewstate value with this code:
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(resp.GetResponseStream());
foreach (HtmlNode input in doc.DocumentNode.SelectNodes("//input"))
{
if (input.Attributes["value"] != null)
{
val = input.Attributes["value"].Value;
if (val.IndexOf("1")!=-1)
{
viewState = val;
}
}
}
and finally, I am sending data using this code:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;
response.Close();
string getUrl = "url";
string postData = String.Format(""+viewstate);
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
getRequest.CookieContainer = new CookieContainer();
getRequest.CookieContainer.Add(cookies);
My main problem is viewState, because if I do not submit the viewstate, it returns the same page to me or if I analyze the viewstate value before sending the data and publishing with the data, it returns me your session. For example, I can log in to facebook, but could not post the data to a website that uses viewState. I could not understand this situation. I think I need to parse the viewstate in the same request with the message, but I know that webrequest cannot be reused. Can you help me?