title: WebApi 2 call using HttpWebrequest/HttpClient
body: <p>I need to make a webApi call to the controller from a C# code .Net 4.5</p>
  
  <p>My Api controller looks like:</p>
  
  <pre><code>[Route("api/GetData/{id}/{createDate}")]
  public List&lt;DataModel&gt; GetData(int id, DateTime createDate)
  {
      var dataDb = new DataDb(SqlConnectionString);
      var result = dataDb .GetSalesData(id, createDate);
      return result;
  }
  </code></pre>
  
  <p>How do i call the above controller using c#, 
  I dont want to pass parameter in url for e.g. "<a href="http://wks337:8989/api/GetData/1/2013-06-11/12337" rel="nofollow">http://wks337:8989/api/GetData/1/2013-06-11/12337</a>" instead add it to header/body (any best approach) rather than Uri.</p>
  
  <p>I tried using HttpWebRequest as:</p>
  
  <pre><code>string serviceUrl = url + methodName + "//";
  dynamic parameterObj = new ExpandoObject();
  parameterObj.id= definitionId;
  parameterObj.createDate= jobDate;
  
  string strParameter = JsonConvert.SerializeObject(parameterObj);
  
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrl);
  request.ContentType = "application/json; charset=utf-8";
  request.Method = "POST";
  using (var streamWriter = new StreamWriter(request.GetRequestStream()))
  {
      streamWriter.Write(parameters);
      streamWriter.Flush();
      streamWriter.Close();
  }
  
  var httpResponse = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>But it always gets me 404 error.
  I know am doing something or entirely wrong, Could anyone guide me to the correct code.</p>
  
  <p>I tried google but example suggested to pass parameter in Url which I dont want.</p>