title: Post request upload PDF file C#
body: <p>I am sending post request with pdf file attached example.pdf - this file is added to project in Visual Studio as "content". Problem is that I am receiving 400 Bad request.
  API server is receiving (IFormFile uploadedFile) but in my case uploadedFile is null.
  Authorization is good, url, headers also. I checked it via postman and it is working properly.
  requestbody in debug mode is '{byte[63933]}'
  How to solve this in C#?</p>
  
  <pre><code>string pathToPdfFile = "Scenarios\DefaultScenario\example.pdf";
  byte[] requestBody = File.ReadAllBytes(pathToPdfFile);     
  
  public static string PostRequestUploadFile(string url, Dictionary&lt;string, string&gt; headersDictionary, byte[] requestbody)
          {
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
              request.Method = "POST";
              if (headersDictionary != null)
              {
                  foreach (KeyValuePair&lt;string, string&gt; entry in headersDictionary)
                  {
                      request.Headers.Add(entry.Key, entry.Value);
                  }
              }
              request.ContentType = "application/pdf";
              Stream dataStream = request.GetRequestStream();
              byte[] byteArray = requestbody;
              dataStream.Write(byteArray, 0, byteArray.Length);
              dataStream.Close();
              try
              {
                  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                  {
                      using (Stream stream = response.GetResponseStream())
                      {
                          using (StreamReader reader = new StreamReader(stream))
                          {
                              return reader.ReadToEnd();
                          }
                      }
                  }
              }
              catch (Exception Ex)
              {
                  return Ex.ToString();
              }
          }
  </code></pre>