form_params 中的编码美元符号导致 $top、$skip 和 $skipToken 被忽略

Encoded dollar sign in form_params causing $top, $skip and $skipToken to be ignored

我试图在通过 Azure Resource Graph 访问虚拟机详细信息时实现分页 API。当我使用 $top 和 $skip 时,我仍然会得到所有的结果,就好像这些选项没有被设置一样。我最好的猜测是两个变量中的美元符号都被编码了,这就是 Azure API 忽略它们的原因。当我使用 PHPStorm 的 HTTP 客户端时,我得到了我正在寻找的结果。

$client = new GuzzleHttp\Client();
$response = $client->request(
    'POST',
    'https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01',
    [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => "Bearer {$authorization_token}",
        ],
        'form_params' => [
            'query'         => "where type =~ 'Microsoft.Compute/VirtualMachines' | project id, name, location, resourceGroup, tags, vmId=properties.vmId, vmSize=properties.hardwareProfile.vmSize, networkInterfaces=properties.networkProfile.networkInterfaces",
            'options'       => [
                '$top'  => 25,
                '$skip' => 0,
            ],
            'subscriptions' => [
                $subscription_id,
            ]
        ],
    ]
);

我是否有更好的方法将这些详细信息传递到 Guzzle 中,以便不对这些特定变量进行编码?

编辑: 添加 PHPStorm HTTP 客户端详细信息:

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
Cache-Control: no-cache
Accept: application/json
Authorization: Bearer <token>
Content-Type: application/json

{
  "subscriptions": [
    "<subscription>"
  ],
  "query": "where type =~ 'Microsoft.Compute/VirtualMachines' | project id, name, location, resourceGroup, tags, vmId=properties.vmId, vmSize=properties.hardwareProfile.vmSize, networkInterfaces=properties.networkProfile.networkInterfaces",
  "options": {
    "$top": 25,
    "$skip": 0
  }
}

感谢sammitch,更正后的代码是:

$client = new GuzzleHttp\Client();
$response = $client->request(
    'POST',
    'https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01',
    [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => "Bearer {$authorization_token}",
        ],
        'json' => [
            'query'         => "where type =~ 'Microsoft.Compute/VirtualMachines' | project id, name, location, resourceGroup, tags, vmId=properties.vmId, vmSize=properties.hardwareProfile.vmSize, networkInterfaces=properties.networkProfile.networkInterfaces",
            'options'       => [
                '$top'  => 25,
                '$skip' => 0,
            ],
            'subscriptions' => [
                $subscription_id,
            ]
        ],
    ]
);