我正在尝试在我的 Laravel 项目中使用 guzzlehttp 使用 POST API。但我的开发服务器上出现错误。这在我的本地系统上运行得很好。 $postArray 两边都正确操作。这是我在 Composer 中的 Guzzle 版本:"guzzlehttp/guzzle": "^7.3"
。
代码:
$response = Http::withHeaders([
"accept: application/json",
"content-type: application/json"
])->post('https://staging.consume.com/testing', $postArray)->json();
错误:
strtolower(): Argument #1 ($string) must be of type string, int given
JSON:
{
"message": "strtolower(): Argument #1 ($string) must be of type string, int given",
"exception": "TypeError",
"file": "/mnt/drive_1/www/deploy-api-2021-07-29-14-25-12/vendor/guzzlehttp/psr7/src/Utils.php",
"line": 28,
"trace": [
{
"file": "/mnt/drive_1/www/deploy-api-2021-07-29-14-25-12/vendor/guzzlehttp/psr7/src/Utils.php",
"line": 28,
"function": "strtolower"
},
{
"file": "/mnt/drive_1/www/deploy-api-2021-07-29-14-25-12/vendor/guzzlehttp/psr7/src/Utils.php",
"line": 189,
"function": "caselessRemove",
"class": "GuzzleHttp\\Psr7\\Utils",
"type": "::"
},
{
"file": "/mnt/drive_1/www/deploy-api-2021-07-29-14-25-12/vendor/guzzlehttp/guzzle/src/Client.php",
"line": 455,
"function": "modifyRequest",
"class": "GuzzleHttp\\Psr7\\Utils",
"type": "::"
},
最佳答案
我遇到了同样的问题,当我搜索时,我到达了这个页面。
这是我解决这个问题的方法。
$response = Http::withHeaders([
"accept" => "application/json",
"content-type" => "application/json"
])->post('https://staging.consume.com/testing', $postArray)->json();
关于php - guzzlehttp 在 Laravel 项目上抛出错误 - strtolower() : Argument #1 ($string) must be of type string, int 给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68581387/