title: System.Net.WebException - Internal Server error 500
body: <p>While I am doing a web API using C# console Application using HttpWebRequest an exception occurs</p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Internal Server Error.</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>string postURL = "";
  ServicePointManager.Expect100Continue = true;
  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(postURL);
  
  webRequest.Method = "POST";
  
  webRequest.Headers.Add("token", "ee22c61a55bd0629c8c8a63a8c8b73ed");            
  
  webRequest.KeepAlive = true;
  webRequest.ContentType = "application/json";
  
  webRequest.Headers.Add("ContentType","application/json");
  int bufferSize = 1024;
  byte[] buffer = new byte[bufferSize];
  int byteCount = 0;
  FileInfo finfo = new FileInfo(@"D:\audio\smallwave.zip");
  webRequest.ContentLength = finfo.Length;
  // webRequest.SendChunked = true;
  
  using (FileStream fileStream = File.OpenRead(@"D:\audio\smallwave.zip"))
  using (Stream requestStream = webRequest.GetRequestStream())
  {
      while ((byteCount = fileStream.Read(buffer, 0, bufferSize)) &gt; 0)
      {
          requestStream.Write(buffer, 0, byteCount);
      }
  }
  
  HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
  // using (WebResponse response = webRequest.GetResponse())
  using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  {
      String result = streamReader.ReadToEnd();
      Console.WriteLine(result);
  }
  </code></pre>
  
  <p>An error is showing like</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Net.WebException' occurred in
    System.dll
    Additional information: The remote server returned an error: (500)
    Internal Server Error.</p>
  </blockquote>