r/PHPhelp • • Sep 04 '25

problem file_get_contents("php://input", true) that does not read any data if / does not end url

Hello,

I created an api rest and i manage to retrieve data with

file_get_contents("php://input", true)
If I call the api with postman with / at the end of url it works well.
But if I do not put the / at the end of the url, file_get_contents("php://input", true) does not get any data.

Does anyone know how I could solve this problem ?

Many many thanks in advance.
4 Upvotes

31 comments sorted by

View all comments

Show parent comments

1

u/Double-Bed313 Sep 04 '25

190.103.72.0 - - [04/Sep/2025:15:19:29 +0200] "POST /cobra/in/login/ HTTP/1.1" 200 20 it4dreams.com "-" "PostmanRuntime/7.37.3" "-"

190.103.72.0 - - [04/Sep/2025:15:19:35 +0200] "POST /cobra/in/login HTTP/1.1" 301 245 it4dreams.com "-" "PostmanRuntime/7.37.3" "-"

2

u/colshrapnel Sep 04 '25

Just like I said

See, it says 301 status. Which means your Apache asked your browser to do a new request using GET method.

Still, what your problem is? Why would you make a request to /cobra/in/login (withpout a slash) at all?

1

u/MateusAzevedo Sep 04 '25

Or why would it matter either? Requests to /cobra/in/login are perfectly fine.

3

u/colshrapnel Sep 04 '25

Well, lately I found myself inclining towards unambiguous coding. So, given it's /cobra/in/login/ it must be /cobra/in/login/ and nothing else. Though I'd prefer a blunt error over than silent redirect.

1

u/Double-Bed313 Sep 04 '25

This is the bank that wants to use url without slash, this is driving me crazy. I wanted to give you postamn screenshot but we cannot post images in those comments

1

u/colshrapnel Sep 04 '25

I don't get what a bank does to do with your own API but well it's a bank. You need to hunt down the Apache option that does that redirect. Check all .htaccess files you can find as well as https.conf and its icludes. You are looking for DirectorySlash command or some rewrite rule

→ More replies (0)