PHP http 请求 GuzzleHttp 执行 POST json 请求

基本使用代码如下:

use GuzzleHttp\Client;

$post_data = ['ids' => [1,2,3], 'session' => '11111111111111111'];
$url = 'https://www.test.com/order/queryById';
$client = new Client();
$headers = ['Content-Type' => 'application/json'];
$response = $client->request('POST', $url, [
    'json' => $post_data, // 提交的json数据
    'headers' => $headers
]);
$contentType = $response->getHeaderLine('Content-Type'); // 获取响应头相关数据
$contents = $response->getBody()->getContents();// 获取响应数据
$linkobj = json_decode($contents, true);// 将响应数据转换成json对象