Php Guzzle curl请求获取空响应正文,但状态为200,且内容长度标头正确

Php Guzzle curl请求获取空响应正文,但状态为200,且内容长度标头正确,php,http,curl,guzzle,Php,Http,Curl,Guzzle,我正在通过Guzzle 3.8.1请求一个超过2MB的Jasper报告(通过Jasper服务器API),并且我得到了一个具有正确内容长度标题但没有响应正文的响应 狂饮请求: 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

我正在通过Guzzle 3.8.1请求一个超过2MB的Jasper报告(通过Jasper服务器API),并且我得到了一个具有正确内容长度标题但没有响应正文的响应

狂饮请求:

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 ***=
答复:

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
如果我通过命令行上的curl(或在浏览器中请求)发出此请求,我将获得预期的报告

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]


在我的例子中,我错误地使用了
MockHandler

您是否尝试过设置用户代理:
$client->setHeader('user-agent','Mozilla/5.0(Macintosh;Intel Mac OS X 10_10_2)AppleWebKit/537.36(KHTML,像Gecko)Chrome/40.0.2214.111 Safari/537.36')@halfer这就是当我使用-v(verbose)时curl命令行工具输出它的方式flag@halfer我正在使用jasper的RESTAPI检索报告。使用jasperserverui,当我通过浏览器点击url或在命令行上点击curl时,报告工作正常。它似乎只给出了一个空洞的回应,用狂饮的口吻通过php@pdizz-您确定curl在从命令行运行时没有设置默认的
User Agent
?@Cyclone I是错误的,看起来guzzle正在发送
guzzle/3.8.1 curl/7.19.7 PHP/5.5.8
,curl正在发送
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
    $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;
}