gpt4 book ai didi

php - Guzzle后置参数问题

转载 作者:可可西里 更新时间:2023-11-01 12:17:56 25 4
gpt4 key购买 nike

当使用 2 个参数进行 POST 请求时:

return $this->perform($client->post("/authenticate",null, array(
"username" => 'radupass',
"password" => '@alcool', //starting with an @
)));

哪里$客户:

/**
* @return \Guzzle\Service\Client
*/
public function getClient()
{
if ($this->_client === null) {
$this->_client = new Guzzle\Service\Client($this->baseUrl, $this->_options);
$this->_client->setDefaultHeaders(array(
"X-WebsiteId" => $this->websiteId,
"X-AccessToken" => $this->accessToken,
));
}
return $this->_client;
}

我得到以下异常:

2013/05/29 11:08:29 [error] [exception.Guzzle\Common\Exception\InvalidArgumentException] exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open lcool for reading' in /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php:58
Stack trace:
#0 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php(25): Guzzle\Http\Message\PostFile->setFilename('@lcool')
#1 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(245): Guzzle\Http\Message\PostFile->__construct('password', '@lcool', NULL)
#2 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(273): Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('password', '@lcool', NULL, false)
#3 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactory.php(127): Guzzle\Http\Message\EntityEnclosingRequest->addPostFiles(Array)
#4 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(256): Guzzle\Http\Message\RequestFactory->create('POST', 'http://api.subs...', Object(Guzzle\Common\Collection), Array)
#5 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(336): Guzzle\Http\Client->createRequest('POST', '/authenticate', NULL, Array)
#6 /home/xxx/site/frontend/components/SubServerClient.php(117): Guzzle\Http\Client->post('/authenticate', NULL, Array)

似乎客户端正在尝试打开一个文件。

编辑

查看我在以下位置看到的 Guzzle 源代码:

https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Http/Message/RequestFactory.php#L88

 if (is_array($body) || $body instanceof Collection) {
// Normalize PHP style cURL uploads with a leading '@' symbol
foreach ($body as $key => $value) {
if (is_string($value) && substr($value, 0, 1) == '@') {
$request->addPostFile($key, $value);
unset($body[$key]);
}
}
// Add the fields if they are still present and not all files
$request->addPostFields($body);
}

如果我想转义那个角色怎么办?

最佳答案

似乎是 cURL 本身的一个已知问题:

Using CURL in PHP to post text data starting with "@"

一种解决方案是使用百分比编码,“@”符号将是“%40”,尽管这需要一些额外的工作。

另见 this线程。

关于php - Guzzle后置参数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16812713/

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