1
私はguzzleを使用してAPIをクエリしています。Laravel + GuzzleHTTP応答データなし?
$client = new Client();
$response = $client->post('xxxxxx',
array(
'headers' => array('Content-Type'=>'application/json'),
'json'=> array(
"type" => 0,
[...]
)
)
);
//$response = json_decode($response);
dd($response->getBody());
これはすべき出力を私にこのような何か:
{
"returnCode": 0,
"success": true
}
ではなく、私は何か他のものを得ます。
Stream {#230 ▼
-stream: stream resource @12 ▼
wrapper_type: "PHP"
stream_type: "TEMP"
mode: "w+b"
unread_bytes: 0
seekable: true
uri: "php://temp"
options: []
}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
誰でも助けてくれますか、私が何を間違えたか教えてください。私は未処理の投稿データを送信したいし、未処理の投稿データを取得したい場合は、保存したい(たとえばdb)。
これは完璧な仕組みです。 jsonオブジェクトを文字列として返してくれることを迷惑にさせる唯一のことです。 '" {"returnCode":0、 "success":true} "。何とか変換することはできますか? – Scarwolf
JSONを文字列にしたいという場合は、既にそれがあります。もしその文字列をPHPオブジェクトにしたいのであれば、単に 'json_decode($ response-> getBody() - > getContents())'を実行してください。 – Loek
はい、後者を意味しています。 – Scarwolf