title: How to read the JSON response content from a XMLHttpRequest?
body: <p><strong>Note: I'm using the <a href="https://github.com/cefsharp/CefSharp" rel="nofollow noreferrer">CefSharp</a> browser for this.</strong></p>
  <h3>Goal</h3>
  <p>I'm trying to read every JSON response from a XMLHttpRequest.</p>
  <h3>What I've tried</h3>
  <pre><code>public class RequestHandler : IRequestHandler
  {
      public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
          IResponse response, UrlRequestStatus status, long receivedContentLength)
      {
          if (request.Headers[&quot;X-Requested-With&quot;] == &quot;XMLHttpRequest&quot; &amp;&amp;
              response.ResponseHeaders[&quot;Content-Type&quot;] == &quot;application/json&quot;)
          {
              var resourceHandler = new ResourceHandler();
              long responseLength;
              string redirectUrl;
              var stream = resourceHandler.GetResponse(response, out responseLength, out redirectUrl);
              using (var streamReader = new StreamReader(stream))
              {
                  var responseContent = streamReader.ReadToEnd();
                  Console.WriteLine(responseContent);
              }
          }
      }
  
      public IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame,
          IRequest request, IResponse response)
      {
          return null;
      }
  
      public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
          bool isRedirect)
      {
          return false;
      }
  
      public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl,
          WindowOpenDisposition targetDisposition, bool userGesture)
      {
          return false;
      }
  
      public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode,
          string requestUrl,
          ISslInfo sslInfo, IRequestCallback callback)
      {
          return false;
      }
  
      public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
      {
      }
  
      public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame,
          IRequest request,
          IRequestCallback callback)
      {
          return CefReturnValue.Continue;
      }
  
      public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
          string host, int port,
          string realm, string scheme, IAuthCallback callback)
      {
          return false;
      }
  
      public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
      {
      }
  
      public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize,
          IRequestCallback callback)
      {
          return false;
      }
  
      public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
          ref string newUrl)
      {
      }
  
      public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
      {
          return false;
      }
  
      public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser)
      {
      }
  
      public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
          IResponse response)
      {
          return false;
      }
  }
  </code></pre>
  <h3>Problem</h3>
  <p>I'm unable to read the JSON response because <em><strong>stream</strong></em> is null.</p>
  <h3>Question</h3>
  <p>How can I read the JSON response content from a XMLHttpRequest?</p>
  <h3>I am very inexperienced in this area. So, if I have left out any useful information: please let me know and I will provide it.</h3>