gpt4 book ai didi

php - Guzzle 请求查询参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:40:34 25 4
gpt4 key购买 nike

我有一个使用 gullzehttp 的方法,我想将它更改为池,并且池实现了 Request 方法

<?php
use GuzzleHttp\Client;
$params = ['password' => '123456'];
$header = ['Accept' => 'application/xml'];
$options = ['query' => $params, 'headers' => $header];
$response = $client->request('GET', 'http://httpbin.org/get', $options);

我需要更改为 Request 方法,但我在文档中找不到如何在 Request 中发送查询字符串变量

<?php
use GuzzleHttp\Psr7\Request;
$request = new Request('GET', 'http://httpbin.org/get', $options);

最佳答案

您需要将查询作为字符串添加到 URI。

为此你可以使用 http_build_queryguzzle helper function将参数数组转换为编码查询字符串:

$uri = new Uri('http://httpbin.org/get');

$request = new Request('GET', $uri->withQuery(GuzzleHttp\Psr7\build_query($params)));

// OR

$request = new Request('GET', $uri->withQuery(http_build_query($params)));

关于php - Guzzle 请求查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42538403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com