PHP: HTTP_Request2 gives zero content length
The result of the HTTP_Request2::send()
method is a little different to curl_exec
. It is not as string, but another type, namely HTTP_Request2_Response
.
To retrieve the response body as a string (a HTTP response contains the headers and a body), use the HTTP_Request2_Response::getBody
method:
...$response = $request->send();$responseBody = $response->getBody();
This should do what you're looking for, $responseBody
then is a string. In more general terms: HTTP_Request2
has an object-oriented interface. This allows to use different adapters (e.g. Curl as well as sockets or you can even write your own one, e.g. for testing) as well as retrieving the response body in a streaming fashion (e.g. with large responses you do not put all into a single string at once).