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

dmag's avatar
Level 6

HTTP client instructed to send POST but sends GET

The issue arose when I was not getting a proper response from a post request to an external api. The response the external api endpoint was returning was that of a GET request, not POST. So it appears that the HTTP facade sends get request instead of post.

$response = Http::withOptions(['verify' => false])
    ->withBasicAuth($this->user, $this->pass)
    ->post($this->apiUrl . '/orders/create', $payload);

dd($response);

/*
Illuminate\Http\Client\Response^ {#7743
  #response: GuzzleHttp\Psr7\Response^ {#7810
    -reasonPhrase: "OK"
    -statusCode: 200
    -headers: array:9 [...]
    -headerNames: array:9 [...]
    -protocol: "1.1"
    -stream: GuzzleHttp\Psr7\Stream^ {#7811 ...}
  }
  +"transferStats": GuzzleHttp\TransferStats^ {#7795
    -request: GuzzleHttp\Psr7\Request^ {#7794
      -method: "GET"
      -requestTarget: null
      -uri: GuzzleHttp\Psr7\Uri^ {#7782
        -scheme: "http"
        -userInfo: ""
        -host: "example.api.com"
        -port: null
        -path: "/orders/create/"
        -query: ""
        -fragment: ""
        -composedComponents: "http://example.api.com/orders/create/"
      }
    }
  }
}
*/
0 likes
5 replies
Sinnbeck's avatar

What do you get if you dd before sending

$response = Http::dd()->withOptions(['verify' => false])
    ->withBasicAuth($this->user, $this->pass)
    ->post($this->apiUrl . '/orders/create', $payload); 
1 like
dmag's avatar
Level 6

@Sinnbeck here's what I get from Http::dd():

Illuminate\Http\Client\Request^ {#7796
  #request: GuzzleHttp\Psr7\Request^ {#7793
    -method: "POST"
    -requestTarget: null
    -uri: GuzzleHttp\Psr7\Uri^ {#7781
      -scheme: "https"
      -userInfo: ""
      -host: "example.api.com"
      -port: null
      -path: "/orders/create"
      -query: ""
      -fragment: ""
      -composedComponents: null
    }
    ...
Sinnbeck's avatar

@dmag if you remove the dd again and do this?

dd($response->redirect());
1 like
dmag's avatar
dmag
OP
Best Answer
Level 6

The issue resolved when I added a trailing slash to the url /orders/create/. Apparently, the POST method in this case somehow was being converted to GET because of the absence of that trailing slash.

2 likes
elendil79's avatar

@dmag Thanks a lot, I had the same problem and solved only add the final trailing slash

1 like

Please or to participate in this conversation.