D
D
Denis Khabibullin2022-02-28 14:42:46
PHP
Denis Khabibullin, 2022-02-28 14:42:46

How to get json request and issue a response to it in PHP?

Hello! I ran into this problem:
there is a resource that sends a json request, namely: "{ "warehouseId": 12345, "partnerWarehouseId": "54321", "skus": [ "1", "2", "3", . .. ] }" to my server, how can I make the response to this json request in the form of information output, namely: "skus" in order?

This code is passing an empty value:
$postData = file_get_contents(' php://input ');
$data = json_decode($postData, true);
echo json_encode($data['skus']);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2022-02-28
@inFureal

$postData = file_get_contents('php://input');
$data = json_decode($postData, true);
echo json_encode($data['skus'] ?? []);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question