php - guzzlehttp 在 Laravel 项目上抛出错误 - strtolower() : Argument #1 ($string) must be of type string, int 给出

标签 php laravel laravel-8 guzzle

我正在尝试在我的 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/

相关文章:

c# - 三重加密在 PHP 和 C# 中没有产生相同的结果

eloquent - laravel toSQL() 中的问号

windows - 我将如何在后台运行 Laravel 5.2 的队列监听器?

php - 四舍五入到最接近和最小的 10 倍数

forms - 在带有 Blade 模板的表单中使用 laravelcollective/html 时防止转义单引号

laravel - 在 Laravel 8 中安装 Laravel/ui 的问题

macos - Laravel Sail & Docker 添加额外站点(多项目)

php - 为什么 composer 降级了我的软件包?

php - 类型 'id' 上不存在属性 'typeof Foods'

PHP - 仅在来自文本的链接中将空格转换为 %20