各位好,我使用curl做一次post,但发现最后返回的结果为array,请大神帮助。
代码如下:
shWin.php
<?php
//$url="http://";
 $url = "http://10.5.103.56/azk/echoRs.php";
//  $data = array (
//   "act" => "botton",
//   "foo" => "bar" 
//  );
$data='文章内容';$ch = curl_init ($url);
//$content = json_encode($data);
 curl_setopt($ch,CURLOPT_HEADER,0);
//curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
//curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 );
$output = curl_exec ( $ch );echo $output;
if($output === false)
{
    echo 'Curl error: ' . curl_error($ch) ;
   // echo 'Curl errorno: ' . curl_errno($ch) ;
  //  echo curl_getinfo($ch);
}
else
{
    
}
curl_close ( $ch );?>
echoRs.php
<?php
print_r ($_POST);?>浏览器显示的结果是:
array()
怎么是这样呢?难道不应该返回文章内容吗?

解决方案 »

  1.   


    <?php
    //$url="http://";
     $url = "http://10.5.103.56/azk/echoRs.php";
    //  $data = array (
    //          "act" => "botton",
    //          "foo" => "bar" 
    //  );
    $data=array('data'=>'文章内容');
     
    $ch = curl_init ($url);
    //$content = json_encode($data);
     curl_setopt($ch,CURLOPT_HEADER,0);
    //curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
    //curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
    curl_setopt ( $ch, CURLOPT_POST, true );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query($data) );
    curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 );
    $output = curl_exec ( $ch );
     
    echo $output;
    if($output === false)
    {
        echo 'Curl error: ' . curl_error($ch) ;
       // echo 'Curl errorno: ' . curl_errno($ch) ;
      //  echo curl_getinfo($ch);
    }
    else
    {
         
    }
     
     
    curl_close ( $ch );
     
    ?>