title: How to send data using webrequest class method?
body: <p>In my application I send data to a PHP server. I got code from the msdn website.</p>
  
  <pre><code>void SendPost()
      {
          var url = "http://www.nuatransmedia.com/ncampaign/mailserver/mail1.php";
  
          // Create the web request object
          HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
          webRequest.Method = "POST";
          webRequest.ContentType = "application/x-www-form-urlencoded";
  
          // Start the request
          webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);    
      }
  
      void GetRequestStreamCallback(IAsyncResult asynchronousResult)
      {
          HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
          // End the stream request operation
          Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);
  
          // Create the post data
          // Demo POST data 
          string postData = "Hello";
  
          byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  
          // Add the post data to the web request
          postStream.Write(byteArray, 0, byteArray.Length);
          postStream.Close();
  
          // Start the web request
          webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
      }
  
      void GetResponseCallback(IAsyncResult asynchronousResult)
      {    
          try
          {
              HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
              HttpWebResponse response;
  
              // End the get response operation
              response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
              Stream streamResponse = response.GetResponseStream();
              StreamReader streamReader = new StreamReader(streamResponse);
              var Response = streamReader.ReadToEnd();
              streamResponse.Close();
              streamReader.Close();
              response.Close();
  
          }
          catch (WebException e)
          {
              // Error treatment
              // ...
          }
      }` void SendPost()
      {
          var url = "http://www.nuatransmedia.com/ncampaign/mailserver/mail1.php";
  
          // Create the web request object
          HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
          webRequest.Method = "POST";
          webRequest.ContentType = "application/x-www-form-urlencoded";
  
          // Start the request
          webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);    
      }
  
      void GetRequestStreamCallback(IAsyncResult asynchronousResult)
      {
          HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
          // End the stream request operation
          Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);
  
          // Create the post data
          // Demo POST data 
          string postData = "Hello";
  
          byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  
          // Add the post data to the web request
          postStream.Write(byteArray, 0, byteArray.Length);
          postStream.Close();
  
          // Start the web request
          webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
      }
  
      void GetResponseCallback(IAsyncResult asynchronousResult)
      {    
          try
          {
              HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
              HttpWebResponse response;
  
              // End the get response operation
              response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
              Stream streamResponse = response.GetResponseStream();
              StreamReader streamReader = new StreamReader(streamResponse);
              var Response = streamReader.ReadToEnd();
              streamResponse.Close();
              streamReader.Close();
              response.Close();
  
          }
          catch (WebException e)
          {
              // Error treatment
              // ...
          }
      }
  </code></pre>
  
  <p>I got mail. But the body messages not show in my mail. Where did I make a mistake? In my PHP code I use <code>postData</code> variable to get my message.</p>