How to forward $_POST with PHP and cURL?

前端 未结 4 1985
长发绾君心
长发绾君心 2021-01-11 13:51

I receive POST request at my PHP script and would like to forward this post call to another script using POST too. How to do this? I can use cURL if it\'s required for this

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 14:20

    If anyone needs this, here's a fully functional cURL request that re-routes $_POST where you want (based on ZZ coder's reply above)

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://urlOfFileWherePostIsSubmitted.com");
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // ZZ coder's part
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
        $response = curl_exec($ch);
        curl_close($ch);
    

提交回复
热议问题