0

I'm using HttpClient in .net 4.5 application to post custom object to Web API service.

Code:

public async Task<HttpStatusCode> Run(Customer customer)
{
     using (var client = new HttpClient())
       {
         client.BaseAddress = new Uri("http://someaddress.net/");
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

         var response = await client.PostAsJsonAsync("api/TestApi", customer)
        }
}

Is there a way to get size of this request before calling PostAsJsonAsync?

Thanks.

Chatumbabub
  • 1,557
  • 2
  • 18
  • 30
  • these SO questions may help http://stackoverflow.com/questions/2331889/how-to-find-the-size-of-a-class-in-c-sharp or http://stackoverflow.com/questions/1128315/find-size-of-object-instance-in-bytes-in-c-sharp - simply measure the sizeof the customer class (if the structure allows such) – jim tollan Feb 16 '16 at 16:40
  • hm, It might be better to convert customer class to json and then measure json itself. – Chatumbabub Feb 16 '16 at 16:47
  • 2
    ... sounds like you've answered your own question :) Probably get Newtonsoft.Json serialiser into the mix and bingo – jim tollan Feb 16 '16 at 16:49

0 Answers0