Php cURL不使用POST数据
我正在试着调试这个,但是我运气不好。我是否正确发送了POST数据Php cURL不使用POST数据,php,debugging,curl,Php,Debugging,Curl,我正在试着调试这个,但是我运气不好。我是否正确发送了POST数据 if (isset($_POST['chrisBox'])) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.associates.com/send-email-orders.php"); curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS,
if (isset($_POST['chrisBox'])) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.associates.com/send-email-orders.php");
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $_POST['chrisBox']);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$ex = curl_exec($curl);
echo 'email';
$email = true;
}
CURLOPT_POSTFILEDS需要URL编码的字符串或数组作为参数。阅读。已经更改了您的示例,现在它使用URL编码的字符串
if (isset($_POST['chrisBox'])) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.associates.com/send-email-orders.php");
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'chrisBox=' . urlencode($_POST['chrisBox']));
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$ex = curl_exec($curl);
echo 'email';
$email = true;
}
在
$\u POST
请求中发送的参数需要采用以下形式:
key=value&foo=bar
您可以使用PHP的函数来实现这一点。它将从数组中创建查询字符串
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($_POST));
如果只想传递一个参数,则仍需要将其包装在数组或对象中
$params = array(
'stack'=>'overflow'
);
http_build_query($params); // stack=overflow
我在想,既然它是表单的一部分,它已经被编码了。上述函数对键->值关系进行编码。是吗?@哇-是的。它创建一个URL编码的查询字符串。任何非法URL字符都将被转义。
$params = array(
'stack'=>'overflow'
);
http_build_query($params); // stack=overflow