我在php中使用了curl,并在"CURLOPT_POSTFIELDS"中设置了参数。我在目标url上使用return$_REQUEST/$_POST来检查我传递的参数是否正确发布。但我无法检查目标页面中发布的参数。
目标url示例:-http://www.eg.com/target
curl_setopt($ipnextec,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);
任何帮助!!
问候Patrick
如果您确实可以访问http://www.eg.com/target,您需要更改使用的流$_REQUEST仅用于表单编码数据。要访问原始json,需要使用
$data = file_get_contents('php://input');
然后,如果您想"覆盖$_POST,请使用
$_POST = json_decode($data, true);