title: How to parse form content in DelegatingHandler
body: <p>I'm trying to create a custom <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/httpclient-message-handlers" rel="nofollow noreferrer">message handler</a> which adds an <code>Authorization</code> header to all requests sent by an <code>HttpClient</code>. In order to compute the value of this header, the path of the request (including query parameters) must be concatenated with the the body of the request (which must have a content type of <code>application/x-www-form-urlencoded</code>).</p>
  <p>Since my use-case is very latency sensitive, I was wondering whether the code below is the most efficient/ fastest way of doing this? Or could it be improved? In particular, is there a better alternative to having to use <code>ReadAsStringAsync</code> to get the form data?</p>
  <pre><code>class AuthorizationHandler : DelegatingHandler
  {
      protected override async Task&lt;HttpResponseMessage&gt; SendAsync(
          HttpRequestMessage request,
          CancellationToken cancellationToken)
      {
          var path = request.RequestUri.PathAndQuery;
          var content = await request.Content.ReadAsStringAsync(cancellationToken);
          // TODO: create &quot;Authorization&quot; header
          return await base.SendAsync(request, cancellationToken);
      }
  }
  </code></pre>