title: WebClient UploadFile The remote server returned an error: (400) Bad Request
body: <p>Trying to upload an xml file, this particular server is returning an error (exception above).
  I have tried another url, on another server (<a href="https://posttestserver.com/post.php" rel="nofollow">https://posttestserver.com/post.php</a>), and the code worked.
  My co-worker was able to upload the same xml file via a Perl Script. </p>
  
  <p>My question is: Is there another way to upload the contents of the file? Tried UploadData, UploadString, got the same error.</p>
  
  <pre><code>// Create the xml document file
  Byte[] buffer = new Byte[ms.Length];
  buffer = ms.ToArray();
  xmlOutput = System.Text.Encoding.UTF8.GetString(buffer);
  string filePath = @"c:\my.xml");
  File.WriteAllText(filePath, xmlOutput);
  
  try
  {
      ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) =&gt; true;
  
      using (WebClient client = new WebClient())
      {
          byte[] rawResponse = client.UploadFile(url, filePath); 
          string response = System.Text.Encoding.ASCII.GetString(rawResponse);    
      }
  }
  catch (WebException ex)
  {
  }
  catch (Exception ex)
  {
  }
  </code></pre>