代码之家  ›  专栏  ›  技术社区  ›  Pankaj Sharma

PHP:返回目标url时未显示curl postfield参数

  •  0
  • Pankaj Sharma  · 技术社区  · 9 年前

    我在php中使用了curl,并在“CURLOPT_POSTFIELDS”中设置了参数。我在目标url上使用return$_REQUEST/$_POST检查传递的参数是否正确发布。但我无法检查目标页面中发布的参数。

    目标url示例:- http://www.eg.com/target

    curl_setopt($ipnesec,CURLOPT_URL,“ http://www.eg.com/target ");

    代码

    $clientId = "AXLAatA9ucEkGt2C9y5SuNRd24Ys4NPod8VJmNNFq5otso1RQRIn";
            $secret = "EGOojWJihcU8wnGTVQivKOsD_ylB5mMdaWmbn_1UWGlqbaugSCOZ";
            $post = array(
                            "key" =>  $clientId,
                            "secret" => $secret   
                        );
    
            $ipnexec = curl_init();
    
            curl_setopt($ipnexec, CURLOPT_URL, "http://www.eg.com/target"); 
            curl_setopt($ipnexec, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ipnexec, CURLOPT_POST, true);
            curl_setopt($ipnexec, CURLOPT_POSTFIELDS, json_encode($post));
            curl_setopt($ipnexec, CURLOPT_RETURNTRANSFER, true);
    
            $ipnresult = curl_exec($ipnexec);
            $result = json_decode($ipnresult);
    

    任何帮助!!

    当做 帕特里克

    1 回复  |  直到 9 年前
        1
  •  2
  •   Steve    9 年前

    如果您确实可以访问位于的端点 http://www.eg.com/target ,您需要更改使用的流$_REQUEST仅用于表单编码数据。要访问原始json,需要使用

    $data = file_get_contents('php://input');

    然后,如果要“覆盖$_POST,请使用

    $_POST = json_decode($data, true);