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

julianov's avatar

Http request not working in laravel

Hello All.

I have to query a WS with laravel, but I am not getting the correct response. If I get the correct response with the curl command in the operating system console.

this is the console command:

curl https://domain:8001 -H "Authorization: token

This is the controller method:

   public function check_user (Request $request){

        $validated = $this->validate($request, [
            'user' => 'required',
        ]);

        $response_user = Http::withHeaders(
            ['Authorization' => 'token'])->get("https://domain:8001");

        return response()->json([
            'status' => true,
            'user' => $response_user,
        ], 201);

    }

With that method controller I get this json response which is not right:

  {"status":true,"user":{"cookies":{},"transferStats":{}}}
0 likes
3 replies
Faith69's avatar

If you would like the HTTP client to automatically retry the request if a client or server error occurs, you may use the retry method. The retry method accepts the maximum number of times the request should be attempted and the number of milliseconds that Laravel should wait in between attempts: $response = Http::retry(3, 100)->post(/*... */);

1 like
julianov's avatar

@Faith69 Thanks.

How can I set the retry pararms with withHeaders pararms?

Like this:

$response_user = Http::retry(3,100)->withHeaders( ['Authorization' => 'token'])->get("https://domain:8001");

but it returns an error.

Please or to participate in this conversation.