Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've just discovered to myself an PhpStorm HTTP client tool, but immediately faced unexpected problem. I am unable to send any POST params to my localhost.

I've tried the following code:

POST https://test.loc/
Content-Type: application/json

{
  "test": "asd"
}

Didn't work. The $_REQUEST array is simply empty.

At the same time, i'm receiving all GET params without problems.

Also tried to send exactly same request to https://httpbin.org/post and received the list of my params back at responce, so I assume that request syntax is ok and HTTP client work well.

So, could anyone please tell what the problem with my local server?

I'm using:

  • PhpStorm 2020.3.1
  • Open Server 5.3.7

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

This issue has nothing to do with PhpStorm. It's just pure PHP and how it handles POST data here.

Try this in your script:

Request Body:
<pre><?= var_dump(file_get_contents('php://input')) ?></pre>

(decode from JSON to see it as an array, e.g. json_decode(file_get_contents('php://input'), true))

PHP decodes POST data when Content-Type: multipart/form-data (in such case php://input is not available) but for your request type you need to handle that yourself (or use a library/framework for that).

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...