title: Send a file via HTTP POST with C#
body: <p>I've been searching and reading around to that and couldn't fine anything really useful.</p>
  
  <p>I'm writing an small C# win app that allows user to send files to a web server, not by FTP, but by HTTP using POST. Think of it like a web form but running on a windows application.</p>
  
  <p>I have my HttpWebRequest object created using something like this </p>
  
  <pre><code>HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest 
  </code></pre>
  
  <p>and also set the <code>Method</code>, <code>ContentType</code> and <code>ContentLength</code> properties. But thats the far I can go.</p>
  
  <p>This is my piece of code:</p>
  
  <pre><code>HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
  req.KeepAlive = false;
  req.Method = "POST";
  req.Credentials = new NetworkCredential(user.UserName, user.UserPassword);
  req.PreAuthenticate = true;
  req.ContentType = file.ContentType;
  req.ContentLength = file.Length;
  HttpWebResponse response = null;
  
  try
  {
      response = req.GetResponse() as HttpWebResponse;
  }
  catch (Exception e) 
  {
  }
  </code></pre>
  
  <p>So my question is basically how can I send a fie (text file, image, audio, etc) with C# via HTTP POST.</p>
  
  <p>Thanks!</p>