title: Can't make Post requests to Web API
body: <p>So I've looked around for an answer for this but nothing I've found even comes close to solving it.</p>
  
  <p>I'm trying to set up a Post method on my Web API but no matter what I do it just gives me an internal server error.</p>
  
  <p>I've tried adding [FromBody] (it's a simple type).</p>
  
  <pre><code>    HttpClient client {get;set;}
  
      public APICall()
          {
           client = new HttpClient
           {
               BaseAddress = new Uri("http://localhost:1472/api/")
            };
  
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-protobuf"));
          }
  
  
      public void PostTimeTaken(long timeTaken)
              {
                  var response = client.PostAsJsonAsync("Logging", timeTaken).Result;
                  if (!response.IsSuccessStatusCode)
                  {
                      Console.WriteLine(response.ReasonPhrase);
                  }
              }
  </code></pre>
  
  <p>and then my controller action looks like this:</p>
  
  <pre><code>public void Post([FromBody] long timeTaken)
          {
              _api.DataBuilder.NumberOfAPICalls += 1;
              _api.DataBuilder.ResponseTimes.Add(timeTaken);
          }
  </code></pre>
  
  <p>I get no error message that could actually explain what's going on, just "Internal server error"</p>
  
  <p>------SOLVED-------</p>
  
  <p>Just in case anyone stumbles across this looking for the same answer, the issue was I was sending the data to the server in an incorrect format, it needed to be ProtoBuf serialised first, code snippet for anyone it might help:</p>
  
  <pre><code>public void PostToAPI(int ThingToSend)
          {
              using (var stream = new MemoryStream())
              {
                  // serialize to stream
                  Serializer.Serialize(stream, ThingToSend);
                  stream.Seek(0, SeekOrigin.Begin);
  
                  // send data via HTTP
                  StreamContent streamContent = new StreamContent(stream);
                  streamContent.Headers.Add("Content-Type", "application/x-protobuf");
                  var response = client.PostAsync("Logging", streamContent);
                  Console.WriteLine(response.Result.IsSuccessStatusCode);
              }
          }
  </code></pre>