zoukankan      html  css  js  c++  java
  • 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就行了

  • 相关阅读:
    【HDU5015】233 Matrix
    【POJ3233】Matrix Power Series
    【POJ3070】Fibonacci
    【NOIP模拟】奇怪的字符串
    【NOIP模拟】超级跳棋
    【NOIP模拟】玛雅文字
    【NOIP模拟】距离
    【闲聊】关于本BLOG
    【NOIP模拟】树
    【NOIP模拟】机器人
  • 原文地址:https://www.cnblogs.com/axl-study/p/4535475.html
Copyright © 2011-2022 走看看