Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tetrapack68's avatar

Laravel 8 - GuzzleHttp POST request with body and header params

Hey guys,

I am facing a problem with the guzzleHttp.

I have a callback URL that requires "application/x-www-form-urlencoded". It also requires to have the same params sent as regular params and as the body params.

So now I am kinda stuck in my code.

    $response = Http::withBody([
        'pile_sn' => $pile_sn,
        'key' => $pile_key
    ])
    ->asForm()
    ->post('EXAMPLE_URL', [
        'pile_sn' => $pile_sn,
        'key' => $pile_key,
    ]);

This apparently does not work as expected. Any help?

Appreciated!

0 likes
1 reply
aurawindsurfing's avatar

Hey @tetrapack68

What usually works for me is nailing down your request in https://www.postman.com/ then export the php code to see what headers, body etc was included. It also helps to just see your generated https request in your browser or in laravel ray.

This way you will be able to experiment with body, params and so on.

Here is example of one I'm using:

$response = Http::post(env('PLAID_ENV') . '/transactions/get', [
            'client_id'    => env('PLAID_CLIENT_ID'),
            'secret'       => env('PLAID_SECRET'),
            'access_token' => $this->company->access_token,
            'start_date'   => $start_date,
            'end_date'     => $end_date,
        ]);

        $transactionCount = $response->json()['total_transactions'];

I also think you mistaken ->withBody() with actual body params, I think your request should look more like this:

$response = Http::asForm()->post('http://example.com/users', [
    'pile_sn' => $pile_sn,
     'key' => $pile_key
]);

Nothing else.

Hope it helps!

1 like

Please or to participate in this conversation.