Pass parameters to web api from console application
<p>I need to communicate with a web api from a console application.</p>

<p>The api needs two variables/parameters passed to it like so:</p>

<pre><code>    [HttpPost("api/loans/range/enroll/{loanStart}/{loanEnd}")]
    public IActionResult PostLoanData(DateTime loanStart, DateTime loanEnd)
    {
        Loans.CreateLoanDates(loanStart, loanEnd);
        return NoContent();
    }
</code></pre>

<p>So in my main method, I did something like this:</p>

<pre><code>static void Main(string[] args)
{
        var LoanDateRange = new Dictionary&lt;string, string&gt;
                {
                    {"loanStart", startDate.ToString()},
                    {"loanEnd", endDate.ToString()}
                };

        var json = JsonConvert.SerializeObject(LoanDateRange);
        HttpClient client = new HttpClient();
        client.PostAsync("http://mybank1.com/api/loans/range/enroll", new StringContent(json, Encoding.UTF8, "application/json"))
            .ContinueWith(task =&gt; {
                var response = task.Result;
                    Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                });
        Console.ReadLine();
 }
</code></pre>

<p>When I run the program I just get a null exception.</p>

<p>How can I give the api what it needs from a console application?  Or maybe, can I change the api so that it can better interact with the console app?</p>

<p>Thanks!</p>