title: How to get post data and request header
body: <p>I am not able to get post data and request header from the below code on button click event.. here i have to pass an url and a string as a post data... </p>
  
  <p>now when i click button i should get response header, request header, post data and content of the url... but i am not able to get the request header and post data from the below code... can any one tell me where i am wrong   </p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
              {
  
                  try
                  {
  
                      string url = txtUrl.Text.Trim();
  
      //HttpWebRequest WebRequestObject = (HttpWebRequest)WebRequest.Create(url);
                     // string result = null;
                      string postData = "This";
                      ASCIIEncoding ObjASCIIEncoding = new ASCIIEncoding();
  
                      byte[] fileData = ObjASCIIEncoding.GetBytes(postData);
  
                      // Create a request using a URL that can receive a post. 
                      WebRequest request = WebRequest.Create(url);
                      // Set the Method property of the request to POST.
                      request.Method = "Post";
                      // Create POST data and convert it to a byte array.    
                      WebHeaderCollection webh = request.Headers;
                      txtRequest.Text = webh.ToString();
  
                      // Set the ContentType property of the WebRequest.
                      request.ContentType = "application/x-wwww-form-urlencoded";
                      // Set the ContentLength property of the WebRequest.
                      request.ContentLength = fileData.Length;
                      // Get the request stream.
                      Stream dataStream = request.GetRequestStream();
                     // StreamReader r = new StreamReader(dataStream);
                     // string p = r.ReadToEnd();
                      // Write the data to the request stream.
                      dataStream.Write(fileData, 0, fileData.Length);
                      // Close the Stream object.
                      dataStream.Close();
                       //Get the response.
  
                      request.Credentials = CredentialCache.DefaultCredentials;
                   //   HttpWebResponse Response = (HttpWebResponse)WebRequestObject.GetResponse();
  
                      WebResponse Response = request.GetResponse();
                     // HttpStatusCode code = Response.StatusCode;
                      //txtStatus.Text = code.ToString();
                     txtResponse.Text = Response.Headers.ToString();
                      // Open data stream:
                      Stream WebStream = Response.GetResponseStream();
  
                      // Create reader object:
                      StreamReader Reader = new StreamReader(WebStream);
  
                      // Read the entire stream content:
  
                      txtContent.Text = Reader.ReadToEnd(); 
                      // Cleanup
                      Reader.Close();
                      WebStream.Close();
                      Response.Close();
  
  
  
                      //  var request = WebRequest.Create("http://www.livescore.com ");
                      //var response = request.GetResponse();
                  }
                  catch(Exception ex)
                  {
                      MessageBox.Show(ex.ToString());
                  }
              }
  </code></pre>