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$client->sendRequest( $request )
を実行すると、200 OK が返され、URL は期待どおりのhttp://localhost:8000/test?access_token=foo
.
別のリクエストがありますが、使用するだけで$client->post(...)
、ストリームを返さずに正常に動作します。
下部の例 ( http://guzzle.readthedocs.org/en/latest/http-client/response.html )を使用してストリームを読み取ろうとしましたfeof
が、存在しないと表示されます。
ここで何が欠けているのか、間違っているのか誰にも分かりますか?