为什么在使用 Pool of Guzzle PHP 库发送请求时不能正确处理西里尔字符?

Why Cyrillic characters are not handled properly when sending requests using Pool of Guzzle PHP library?

我正在使用 Guzzle 将请求发送到外部 API 端点。

在我的请求中有一个文本查询值 - 'https://api_endpoint/'。 '?text='.$text

当我一个一个发送请求时:

$response = $client->request(
            'GET',
            ''https://api_endpoint/' . '?text=' .$text,
        );

它适用于文本字段中的任何语言。但是,当我第一次迭代另一个查询值并创建请求数组然后使用 Pool:

发送这些请求时
$responses = Pool::batch($client, $requests, array(
        'concurrency' => 15,
    ));

在这种情况下,如果请求中的文本字段是用西里尔文编写的,我会从 API 端点收到“错误请求”。但是,如果文本字段是拉丁字符,则一切正常。我一个一个发送请求的情况也是如此。

我假设使用 Guzzle Pool 时编码有问题。

如何修复或解决此问题?

这不是 Guzzle 的问题。您必须在连接之前对 $text 进行 urlencode。执行 urlencode($text) 或使用 Guzzle 的 query 选项:

$response = $client->request(
    'GET',
    'https://api_endpoint/',
    ['query' => ['text' => $text]],
);