title: C#: How to POST large string via WebRequest?
body: <p>how can i upload a large string (in my case XML with BLOB) with POST without getting Timeout with GetResponse?</p>
  
  <p>Changing the timeout helps, but this isn't really a solution.
  If the Server is really death or the POST was interrupted i have to wait for the extrem large timeout.</p>
  
  <p>Any Idea?</p>
  
  <pre><code>HttpWebRequest webRequest = null;
  string response = "";
  byte[] bytes = Encoding.UTF8.GetBytes(xml);
  
  try
  {
      webRequest = (HttpWebRequest)WebRequest.Create("http://" + this.host + ":" + this.port);
      webRequest.ContentType = "application/x-www-form-urlencoded";
      webRequest.Method = "POST";
      webRequest.Timeout = 5000;
  
      webRequest.ContentLength = bytes.Length;
      using (Stream requeststream = webRequest.GetRequestStream())
      {
          requeststream.Write(bytes, 0, bytes.Length);
          requeststream.Close();
      }
  
      using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
      {
          using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
          {
              response = sr.ReadToEnd().Trim();
              sr.Close();
          }
          webResponse.Close();
      }
  }
  catch(Exception ex)
  {
      MessageBox.Show(ex.ToString());
  }
  return response;
  </code></pre>