title: How to post file and data to api using httpclient
body: <p>I am at learning phase and i want to post file and data to api using httpclient. 
  i have tried this. 
  Here is my controller code</p>
  
  <p>string baseUrl = ServerConfig.server_path + "/api/Payment/AddMedicineOrder";
              Dictionary parameters = new Dictionary();</p>
  
  <pre><code>        parameters.Add("username",user.Username);
          parameters.Add("FullName", FullName);
          parameters.Add("Phone", Phone);
          parameters.Add("CNIC", CNIC);
          parameters.Add("address", address);
          parameters.Add("Email", Email);
          parameters.Add("dateofbirth", dateofbirth.ToShortDateString());
          parameters.Add("Gender", Gender);
          parameters.Add("PaymentMethod", PaymentMethod);
          parameters.Add("Title", Title);
          parameters.Add("PhramaList", medList);
  
  
  
         HttpClient client = new HttpClient();
              client.BaseAddress = new Uri("https://localhost:44391/");
              MultipartFormDataContent form = new MultipartFormDataContent();
              HttpContent content = new StringContent("fileToUpload");
              HttpContent DictionaryItems = new FormUrlEncodedContent(parameters);
              form.Add(content, "fileToUpload");
              form.Add(DictionaryItems, "medicineOrder");
     var stream = PostedPrescription.InputStream;
              content = new StreamContent(stream);
              content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
              {
                  Name = "fileToUpload",
                  FileName = PostedPrescription.FileName
              };
              form.Add(content);
  
              var response =await client.PostAsync("/api/Payment/AddMedicineOrder", form);
              var k =response.Content.ReadAsStringAsync().Result;
  </code></pre>
  
  <p>How to pass this in Web api Method</p>
  
  <pre><code>   [HttpPost]
              public async Task&lt;API&gt; AddMedicineOrder()//string key, [FromUri]MedicineOrder medicineOrder
              {
                  var request = HttpContext.Current.Request;
                  bool SubmittedFile = (request.Files.Count != 0);
                  this.Request.Headers.TryGetValues("medicineOrder", out IEnumerable&lt;string&gt; somestring);
  
                  var k = somestring;
    return OK("Success");
              }
              catch (Exception ex)
              {
                  return InternalServerError("Technical Error.");
              }
  </code></pre>
  
  <p>please help me. Thanks in advance</p>