Answer the question
In order to leave comments, you need to log in
How to accept POST json request in php?
Hello! There was a question with which I am excruciated already some days.
There is a service that sends a request in json format to the specified POST page, but I need to catch it on my page and add elements to the database.
The documentation says:
Request example:
POST /page.php HTTP/1.1
Host: host.host
Authorization: Bearer XXXXX
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache
{
"date": "2017-04-25T01:29:20.4520214+00:00",
"stocks": [
{
"nnt": 111173,
"qnt": 5,
"man": "man",
"prcRet": 117.99,
"name": "name",
"dtComing": "2017-08-09T00:00:00 + 07:00"
}
]
}
HTTP/1.1 202 Accepted
[]
header('content-type: application/json');
$v = json_decode(file_get_contents('php://input'));
echo json_encode($v);
Answer the question
In order to leave comments, you need to log in
parsiphp://input
// твои данные тут
$input = json_decode(file_get_contents("php://input"), true);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question