title: Unable to Parse response as JSON error Symfony
body: <p>I have a controller that sends a get request and then tries to parse the response as a JSON. However, requesting it through the browser returns a valid JSON object. I'm getting a 500 error that says 'Exception: Unable to parse response as JSON' and points to <code>JsonHandler.php</code> in the <code>Httpful</code> library. I looked through the file and it is because the body is empty. 
  I am confused since the request url is valid and returns a valid JSON object. </p>
  
  <p><code>Controller.php</code> </p>
  
  <pre><code>        Authorization::checkUser();
          $request = $this-&gt;request;
  
          $callback = $request-&gt;query-&gt;get('callback');
          $url = 'http://example.com/api/get_recent_posts/?' . http_build_query(
              [
                  'count'     =&gt; 20,
                  'post_type' =&gt; 'schedule_show',
                  'page'      =&gt; (int) $request-&gt;query-&gt;get('page', 1),
                  'order'     =&gt; 'ASC',
                  'orderby'   =&gt; 'title',
                  'include'   =&gt; 'id,title',
                  '_'         =&gt; (int) $request-&gt;query-&gt;get('_', time()),
              ]
          );
  
          /** @var \Httpful\Response $APIResponse */
  
          $APIResponse = \Httpful\Request::get($url, 'application/json')-&gt;send();
          $data = $APIResponse-&gt;body;
          $response = new JsonResponse($data);
  
          $response-&gt;setCallback($callback);
  
          return $response;
  </code></pre>
  
  <p>JSON Response: </p>
  
  <pre><code>     {  
     "status":"ok",
     "count":20,
     "count_total":70,
     "pages":4,
     "posts":[  
        {  
           "id":2473,
           "title":"ACOUSTIC ROOTS"
        },
        {  
           "id":2531,
           "title":"AFRIKA REVISITED"
        },
        {  
           "id":2542,
           "title":"AMANECER RANCHERO"
        },
        {  
           "id":2551,
           "title":"APNIVANI"
        },
        {  
           "id":2504,
           "title":"APT 613 LIVE"
        },
        {  
           "id":6229,
           "title":"ATMOSPHERE"
        },
        {  
           "id":2532,
           "title":"BLACK ON BLACK"
        },
        {  
           "id":2550,
           "title":"BOUYON RASIN"
        },
        {  
           "id":2462,
           "title":"CAN-ROCK"
        },
        {  
           "id":2534,
           "title":"CARIBBEAN FLAVOUR"
        },
        {  
           "id":5288,
           "title":"CHUO TOP 30"
        },
        {  
           "id":6060,
           "title":"CINEMASCOPE"
        },
        {  
           "id":2930,
           "title":"CITY SLANG"
        },
        {  
           "id":2524,
           "title":"CYPHER"
        },
        {  
           "id":2484,
           "title":"D&amp;#8217;UN EXTR\u00caME \u00c0 L&amp;#8217;AUTRE"
        },
        {  
           "id":2478,
           "title":"DEMOCKERY&amp;#8217;S DEMISE"
        },
        {  
           "id":2438,
           "title":"DEMOCRACY NOW!"
        },
        {  
           "id":2546,
           "title":"ETHIOPIAN SHOW"
        },
        {  
           "id":5930,
           "title":"FREESTYLE"
        },
        {  
           "id":6247,
           "title":"FR\u00c9QUENCE ANTILLAISE"
        }
     ]
  }
  </code></pre>
  
  <p>The AJAX request:</p>
  
  <pre><code>$.ajax('/shows/select/load', {
    data: {
      count: 20,
      post_type: 'schedule_show',
      page: this.page_current,
      order: 'ASC',
      orderby: 'title',
      include: 'id,title'
    },
    dataType: 'jsonp',
    context: this,
    success: this.loadShows
  });
  </code></pre>
  
  <p>Am I missing something?</p>
  
  <p>Edit: 
  Method that tries to parse the body and throws the exception.</p>
  
  <p>JsonHandler.php: </p>
  
  <pre><code>public function parse($body)
      {
          $body = $this-&gt;stripBom($body);
          if (empty($body))
              return null;
          $parsed = json_decode($body, $this-&gt;decode_as_array);
          if (is_null($parsed) &amp;&amp; 'null' !== strtolower($body))
              throw new \Exception("Unable to parse response as JSON");
          return $parsed;
      }
  </code></pre>
  
  <p>For debugging purposes I added these var_dump statements:</p>
  
  <pre><code>public function parse($body)
      {
          var_dump($body);
          $body = $this-&gt;stripBom($body);
          var_dump($body);
          if (empty($body))
              return null;
          var_dump($this-&gt;decode_as_array);
          $parsed = json_decode($body, $this-&gt;decode_as_array);
          var_dump($parsed);
          if (is_null($parsed) &amp;&amp; 'null' !== strtolower($body))
              throw new \Exception("Unable to parse response as JSON");
          return $parsed;
      }
  </code></pre>
  
  <p>This returned:</p>
  
  <pre><code>string(1) " " 
  string(1) " " 
  bool(false) 
  NULL
  </code></pre>