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

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

PhpStorm HTTP client. Unable to pass POST params to localhost

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...