没有得到Guzzle的预期回应
我正在尝试构建一个端点,该端点使用Slim PHP框架将传递给它的数据转发到API,但我无法从Guzzle请求中获取响应。
$app->map( '/api_call/:method', function( $method ) use( $app ){
$client = new GuzzleHttp\Client([
'base_url' => $app->config( 'api_base_url' ),
'defaults' => [
'query' => [ 'access_token' => 'foo' ],
]
]);
$request = $client->createRequest( $app->request->getMethod(), $method, [
'query' => $app->request->params()
]);
var_dump( $client->send( $request )->getBody() );
})->via( 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' )->conditions( [ 'route' => '.+?' ] );`
然后这给了我...
object(GuzzleHttp\Stream\Stream)[59]
private 'stream' => resource(72, stream)
private 'size' => null
private 'seekable' => boolean true
private 'readable' => boolean true
private 'writable' => boolean true
private 'meta' =>
array (size=6)
'wrapper_type' => string 'PHP' (length=3)
'stream_type' => string 'TEMP' (length=4)
'mode' => string 'w+b' (length=3)
'unread_bytes' => int 0
'seekable' => boolean true
'uri' => string 'php://temp' (length=10)
...而不是我所期待的“酷”的回应。
如果我只是var_dump我得到一个200 OK,网址是我期望的,.$client->sendRequest( $request )
http://localhost:8000/test?access_token=foo
我有另一个请求,但只使用,它工作正常,没有给我流的东西回来。$client->post(...)
我尝试使用底部的示例(http://guzzle.readthedocs.org/en/latest/http-client/response.html)阅读流,但它告诉我不存在。feof
有人知道我在这里错过了什么或做错了什么吗?