PHP:curl postfield参数未显示以返回目标网址

时间:2016-07-27 13:41:14

标签: php curl php-5.3

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

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

  
    

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

  

CODE

$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 个答案:

答案 0 :(得分:1)

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

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

然后如果你想"覆盖$ _POST,请使用

$_POST = json_decode($data, true);