title: Constructing a POST request to a rest server in c#
body: <p>I am attempting to construct a POST request to a REST server, based on the following documentation:</p>
  
  <p><a href="http://appsensor.org/docs/v2.3.0/api/ui/index.html#!/RestRequestHandler/resource_RestRequestHandler_addEvent_POST" rel="nofollow noreferrer">http://appsensor.org/docs/v2.3.0/api/ui/index.html#!/RestRequestHandler/resource_RestRequestHandler_addEvent_POST</a> </p>
  
  <p>I have been using the following code that I have written:</p>
  
  <pre><code>    public async Task&lt;HttpResponseMessage&gt; events()
      {
          try
          {
              client.BaseAddress = new Uri("http://localhost:8085/");
          }
          catch (InvalidOperationException)
          { }
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
          client.DefaultRequestHeaders.Add("X-Appsensor-Client-Application-Name2", "myclientapp");
          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "api/v1.0/events");
          request.Content = new StringContent("AE3",
                                              Encoding.UTF8,
                                              "application/json");//CONTENT-TYPE header
  
  
          HttpResponseMessage response = await client.PostAsJsonAsync("api/v1.0/events", request);
  
          System.Diagnostics.Debug.WriteLine(response.ToString());
          return response;
      }
  </code></pre>
  
  <p>But this is the response I get:</p>
  
  <pre><code>StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: 
  System.Net.Http.StreamContent, Headers:
  
  {
    Connection: close
    Date: Sun, 04 Mar 2018 23:46:17 GMT
    Server: Apache-Coyote/1.1
    Content-Length: 402
    Content-Type: text/plain; charset=UTF-8
  }
  </code></pre>
  
  <p>What is it about the post request that is incorrect?</p>