search

Home  >  Q&A  >  body text

thinkphp - When writing api, when to use $_POST to receive post messages, and when to use php://input?

Now we need to write an api interface, using the post method. Other companies send json data to this api post
But here comes the problem. When I tested it myself, I used $_POST to receive the data at the beginning. When simulating sending, I used PHP's curl mode to post it, and everything was normal. Then when the other party called the api, it said it failed. When I saw it, the received data was empty. I used Fiddler to simulate the post request, and it also failed. It is indeed empty, $_POST cannot receive data, and then I use php://input to receive it successfully. However, I don’t know why, if I use php://input, my php uses curl to simulate the post, but it can’t be received! ! ! !
That is to say
curl post =>> $_POST
Other normal posts =>> php://input
What is this, I Baidu it

I don’t see why either

怪我咯怪我咯2697 days ago1148

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-07-07 10:36:43

    Read more documentation

    When the Content-Type of the HTTP POST request is application/x-www-form-urlencoded or multipart/form-data, the variables will be passed into the current script in the form of an associative array

    http://php.net/manual/zh/rese...

    reply
    1
  • Cancelreply