如何在 Guzzle 中获取正文?
How to get body in Guzzle?
我使用这个请求:
$client = new \GuzzleHttp\Client();
$options = [
'form_params' => [
"tip" => "P",
"voen" => "V",
"voen" => $voen,
"submit" => "Yoxla",
],
];
$res = $client->request('POST', 'https://www.ebyn/payerOrVoenChecker.jsp', $options);
dd($res->getBody());
结果我得到这个:
Stream {#340 ▼
-stream: stream resource @424 ▼
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: []
}
那么,如何得到实体,就是HTML页面呢?
您的解决方案:
$res->getBody()->getContents();
查看 this answer 了解详情。
我使用这个请求:
$client = new \GuzzleHttp\Client();
$options = [
'form_params' => [
"tip" => "P",
"voen" => "V",
"voen" => $voen,
"submit" => "Yoxla",
],
];
$res = $client->request('POST', 'https://www.ebyn/payerOrVoenChecker.jsp', $options);
dd($res->getBody());
结果我得到这个:
Stream {#340 ▼
-stream: stream resource @424 ▼
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: []
}
那么,如何得到实体,就是HTML页面呢?
您的解决方案:
$res->getBody()->getContents();
查看 this answer 了解详情。