dragon321723 2015-03-16 07:35
浏览 151

$ _POST通过cURL无法正常工作

Im trying my hand at using curl to post some data, I am not reciving my post content and can not find the source of the problem

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";
} ?>

Every time I get my error response meaning the post data is not going through. I have tried everything I could think of to trouble shoot;I must be over looking something I am simply not yet familiar with?

  • 写回答

3条回答 默认 最新

  • doq91130 2015-03-16 12:17
    关注

    Please set CURLOPT_URL to 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
    ?>
    

    With curl_getinfo() - Gets information about the last transfer. For more detail read below link:- http://php.net/manual/en/function.curl-getinfo.php

    I have edited the answer, The reason for error is not curl.

    http_build_query($data, '', '&');
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度