php跨域传输(curl)

 public function post_data($url,$data){
    $ch = curl_init();      
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址    
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 ); //超时断开时间    
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);   //POST的数据
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //是否接收返回数据
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data)) );//网页头文件                                                                                                                 
     $result = curl_exec($ch);
     echo  $result;
    }

 

 

接收页面

$raw_post_data = file_get_contents('php://input', 'r');

需要再将数据进行处理;最好在传输页面将数据json_encode这边在json_decode就行了

posted @ 2015-05-28 11:40  正则表达狮  阅读(710)  评论(0编辑  收藏  举报