title: Setting the ContentType header when sending MultipartFormDataContent using HttpClient
body: <p>I am using HttpClient to upload a file to a WebAPI resource using the code below. Since I am using MultipartFormDataContent, the request message content type is set to multipart/form-data. In WebAPI, I am checking the content header to only allow text/plain media type. So, where do I set the content header for the file type if I am using HttpClient with MultipartFormDataContent.</p>
  
  <pre><code>try
  {
      var content = new MultipartFormDataContent();
  
      string filePath = Server.MapPath("~/Content/" + "demo.txt");
  
      var filestream = new FileStream(filePath, FileMode.Open);
  
      var fileName = System.IO.Path.GetFileName(filePath);
  
      content.Add(new StreamContent(filestream), "file", fileName);
  
      var requestMessage = new HttpRequestMessage()
      {
              Method = HttpMethod.Post,
              Content = content,
              RequestUri = new Uri("http://localhost:64289/api/uploads/"), 
          };
  
      var client = new HttpClient();
  
      client.DefaultRequestHeaders.Add("Accept", "application/json");
  
      HttpResponseMessage response = await client.SendAsync(requestMessage);
  
      if (response.IsSuccessStatusCode)
      {
                      /// 
      }
  }
  catch (Exception e)
  {
                  throw;
  }
  </code></pre>