php 发送curl跨域请求,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就行了
原文:http://www.cnblogs.com/axl-study/p/4535475.html
總結
以上是生活随笔為你收集整理的php 发送curl跨域请求,php跨域传输(curl)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js的弹出框
- 下一篇: openstack虚拟机支持USB 重定