1
はresponse.txt
の内容です:Guzz 6を使ってファイルから応答を模擬する方法は?ここ
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 15 Feb 2016 18:25:28 GMT
Content-Type: application/json;charset=utf-8
{
"field1": "a",
"field2": "b",
}
私が試した:
$stream = Psr7\stream_for(file_get_contents('response.txt'));
$response = new Response(200, ['Content-Type' => 'application/json'], $stream);
dd($response->getBody());
をどの出力:だから私は行う方法、response.txt
にJSONコンテンツを取得することはできません
object(GuzzleHttp\Psr7\Stream)#3 (7) {
["stream":"GuzzleHttp\Psr7\Stream":private]=>
resource(26) of type (stream)
["size":"GuzzleHttp\Psr7\Stream":private]=>
NULL
["seekable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["readable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["writable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["uri":"GuzzleHttp\Psr7\Stream":private]=>
string(10) "php://temp"
["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
array(0) {
}
}
それ?私が欲しいのは次のようなものです:
array('field1'=>'a','field2'=>'b');
は実際に私が使用し、 '$対応 - > getBody() - >のgetContent()' – Phoenix
のgetContentsストリームのみで、残りを返す私の問題を解決します。体全体を安全に取得したい場合は、文字列にキャストする必要があります。 –