Reputation: 4455
I am trying to consume a POST API using guzzlehttp in my Laravel project. But I am getting an error on my dev server. This is working perfectly on my local system. $postArray is manipulating correctly both side. This is my Guzzle version in Composer: "guzzlehttp/guzzle": "^7.3"
.
Code:
$response = Http::withHeaders([
"accept: application/json",
"content-type: application/json"
])->post('https://staging.consume.com/testing', $postArray)->json();
Error:
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": "::"
},
Upvotes: 2
Views: 4447
Reputation: 21
I faced the same problem, and when I searched, I arrived at this page.
Here's how I solved it.
$response = Http::withHeaders([
"accept" => "application/json",
"content-type" => "application/json"
])->post('https://staging.consume.com/testing', $postArray)->json();
Upvotes: 2