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

我正在尝试通过 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

  }

}


慕的地8271018
浏览 198回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP