title: Sending POST data with C#
body: <p>This is the method that I'm trying to use to send POST data to a URL and bring back its response:</p>
  
  <pre><code>public string sendPOST(string URL, string postData)
  {
      byte[] byteArray;
      Stream webpageStream;
      StreamReader webpageReader;
      String webpageContent;
  
      byteArray = Encoding.UTF8.GetBytes(postData);
      _webRequest = WebRequest.Create(URL);
      _webRequest.Method = "POST";
      _webRequest.ContentType = "application/x-www-form-urlencoded";
      _webRequest.ContentLength = byteArray.Length;
  
      webpageStream = _webRequest.GetResponse().GetResponseStream();
      webpageStream.Write(byteArray, 0, byteArray.Length);
      webpageStream.Close();
  
      webpageReader = new StreamReader(webpageStream);
  
      webpageContent = webpageReader.ReadToEnd();
  
      return webpageContent;
  }
  </code></pre>
  
  <p>I got a lot of this code from the MSDN web page so i know I'm roughly on the right track... but when I call the method using:</p>
  
  <pre><code>string test = webHelper.sendPOST("http://google.com", "var=1");
  MessageBox.Show(test);
  </code></pre>
  
  <p>The application just locks up. I have debugged the method and as far as I can see the code runs fine up till this line:</p>
  
  <pre><code>webpageStream = _webRequest.GetResponse().GetResponseStream();
  </code></pre>
  
  <p>I have tried wrapping it up in a try block but no exeptions are thrown at all.</p>
  
  <p>Does anyone have enough experience with web requests to help me out?</p>
  
  <p>Thanks a lot :)</p>