2
votes

I am making a request through Guzzle 3.8.1 for a Jasper report (via the Jasper Server API) that is over 2MB and I'm getting a response with the correct Content-Length header but no response body.

Guzzle request:

GET /jasperserver/rest_v2/reports/projects/i3app_suite/Resource/BulkShiftExport.csv?ACCOUNT_ID=2&START_DATETIME=2015-01-01&END_DATETIME=2015-01-31 HTTP/1.1
Host: jasper.i3app:8080
User-Agent: Guzzle/3.8.1 curl/7.19.7 PHP/5.5.8
Authorization: Basic ***=

Response:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: Wed, 31 Dec 1969 17:00:00 MST
P3P: CP="ALL"
Set-Cookie: JSESSIONID=F0B0F72B65A8145B45DA9DB2BACE53D8; Path=/jasperserver/; HttpOnly, userLocale=en_US;Expires=Fri, 13-Feb-2015 18:56:44 GMT;HttpOnly
Content-Disposition: attachment; filename="BulkShiftExport.csv"
output-final: true
Content-Type: application/vnd.ms-excel
Content-Length: 2173897
Date: Thu, 12 Feb 2015 18:57:02 GMT

If I make this request through curl on the command line (or request it in a browser) I get the report as expected

GET /jasperserver/rest_v2/reports/projects/i3app_suite/Resource/BulkShiftExport.csv?ACCOUNT_ID=2&START_DATETIME=2015-01-01&END_DATETIME=2015-01-30 HTTP/1.1
Authorization: Basic ***=
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Host: jasper.i3app:8080
Accept: */*


< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Cache-Control: private
< Expires: Wed, 31 Dec 1969 17:00:00 MST
< P3P: CP="ALL"
< Set-Cookie: JSESSIONID=AF1BF885354AF3E352DD9E18FA044A4B; Path=/jasperserver/; HttpOnly
< Set-Cookie: userLocale=en_US;Expires=Fri, 13-Feb-2015 19:03:42 GMT;HttpOnly
< Content-Disposition: attachment; filename="BulkShiftExport.csv"
< output-final: true
< Content-Type: application/vnd.ms-excel
< Content-Length: 2113902
< Date: Thu, 12 Feb 2015 19:03:49 GMT
< 
{ [data not shown]

The only difference I could see was Accept: */* in the curl request. I tried adding that header to the guzzle request and got the same result.

When making the request through the Guzzle client it appears to take the same amount of time (5-6 seconds) to receive the response, and it sets the Content-Length header, but the response body is empty. Why am I getting an empty response body though Guzzle which is using curl but not when using curl on the command line? Is there an option I need to set to make this work?

    $request = $this->getGuzzleClient()->createRequest('GET');

    $config = $this->getConfig();
    $url = new Url(
        $config['scheme'],
        $config['host'],
        $config['user'],
        $config['pass'],
        $config['port'],
        $config['path'] . $reportPath . '.' . $format,
        new QueryString($parameters)
    );
    $request->setUrl($url);

    $response = $request->send();

...

public function getGuzzleClient()
{
    if (!$this->restClient) {
        $client = new GuzzleClient();
        $this->setRestClient($client);
    }
    return $this->restClient;
}
1
Have you tried setting the user-agent: $client->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36');Cyclonecode
@halfer That is how curl command line tool outputs it when I use -v (verbose) flagpdizz
@halfer I'm using jasper's REST api to retrieve the report. The report works fine using the jasperserver ui, and when I hit the url through the browser or curl on the command line. It only seems to give an empty response using guzzle through phppdizz
@pdizz - Are you sure that curl isn't setting a default User-Agent when running from the commandline?Cyclonecode
@Cyclone I was wrong, It looks like guzzle is sending Guzzle/3.8.1 curl/7.19.7 PHP/5.5.8 and curl is sending curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 for User-Agentpdizz

1 Answers

0
votes

In my case, I was using MockHandler mistakenly.