如何在 HTTP 请求的正文中返回 php 脚本响应?有一个要求:
$ curl 'http://127.0.0.1:8000/findMin.php' -X POST -H 'Content-Type: application/json' --data-binary '{"elements":
[40,8,511,14,22]}'
接下来是一个 php 脚本,它在“元素”中查找最小元素。问题是如何在 HTTP 响应正文中返回一个 json 对象?下面是脚本:
<?php
$elements = json_decode(file_get_contents('php://input'));
return min($elements["elements"]);
这就是他们返回的方式
JSON: