以下の内容はhttps://iww.hateblo.jp/entry/20260224/cURLより取得しました。


PHPで cURLを使ってJSONの送受信をする

オブジェクトをJSONにして送信して、応答のJSONをオブジェクトにして返す関数

<?
    function sendJSON(string $url, object $sendObj): false|object
    {
        // 準備
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($sendObj));
        curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        // 送信、受信
        $recvText = curl_exec($curl);
        $error = curl_error($curl);
        curl_close($curl);

        // エラーチェック
        if($error){
            echo("送信エラー: " . $error);
            return false;
        }

        // データチェック
        $recvObj= json_decode($recvText);
        if(json_last_error() !== JSON_ERROR_NONE){
            echo("JSONデコードエラー: " . json_last_error_msg());
            return false;
        }

        return $recvObj;
    }



以上の内容はhttps://iww.hateblo.jp/entry/20260224/cURLより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14