Say I have a HttpRequestMessage object built like this:
var request = new HttpRequestMessage(HttpMethod.Post, uploadUrl)
{
Content = new ObjectContent(myObject, new JsonMediaTypeFormatter())
};
Which I will send like so:
using (var client = new HttpClient())
{
var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
Is there a way to calculate the size (in bytes) of the request payload before POSTing it? The reason I ask, is because I will be submitting this request to a 3rd party API and I know the API will reject my request if it exceeds a pre-determined max size. I figured if I could calculate the size of the payload in the request I could avoid posting requests that exceed this max size.