我尝试使用curl发布一些数据,我没有收到我的帖子内容,无法找到问题的根源
curl.PHP
<?PHP
$data = array("user_email" => "22" , "pass" => "22" );
$string = http_build_query($data);
$ch = curl_init("http://localhost:8888/290_project/test.PHP"); //this is where post data goes too, also starts curl
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch) //ends curl
?>
test.PHP的
<?PHP
if(isset($_POST['user_email'], $_POST['pass'])) {
$name = $_POST['user_email'];
$pass = $_POST['pass'];
echo $name;
echo $pass;
} else {
echo "error";
} ?>
每次我得到我的错误响应意味着帖子数据没有通过.我已经尝试了一切我能想到的麻烦射击;我一定是在寻找一些我根本不熟悉的东西?
解决方法:
请将CURLOPT_URL设置为http://localhost:8888 …..
<?PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:8888/290_project/test.PHP");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
if(!curl_errno($ch)){
$info = curl_getinfo($ch);
} else {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch) //ends curl
?>
使用curl_getinfo() – 获取有关上次传输的信息.
欲了解更多详情,请阅读以下链接: – http://php.net/manual/en/function.curl-getinfo.php
我编辑了答案,错误的原因不是卷曲.
http_build_query($data, '', '&');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。