title: Post data to website with cookies and viewState
body: <p>I want to post data to a website. I handle the cookies with this code :</p>
  
  <pre><code>CookieCollection cookies = new CookieCollection();
           request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  </code></pre>
  
  <p>I handle viewstate value with this code: </p>
  
  <pre><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;
                        }
                     }
                }
  </code></pre>
  
  <p>and finally I'm posting data with this code:</p>
  
  <pre><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);
  </code></pre>
  
  <p>My main problem is viewState because if I don't post viewstate it returns me the same page or  if I parse viewstate value before the posting data and post with data it returns me your session timed out. For example I'm able to login facebook but I could not post data to website which uses viewState. I couldn't figure out this situation. I think I have to parse viewstate in the same request with post but I know that webrequest can not be reused. Can you help me?</p>