0

我为我的网站开发了一个 API。API 100% 正确工作。但是我将它设计为从这种 POST 参数中捕获和执行函数$_POST['functionName']; $_POST['parameter'];现在,在请求页面中我想将它们发送为$_POST,我设法处理了它。但我的问题是,如何创建一个函数,可以使用curl. 这是我向我的API发送请求的代码。

$url = 'http://localhost/myapi/api.php';
$postfields['functionName'] = "myFunction";
$postfields['parameter'] = "1";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
$results = json_decode($data, true);
curl_close($ch);
4

0 回答 0