GET 数据请求
$url = "http://www.xxxx.com?user=111";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);$out = curl_exec($ch);curl_close($ch);$obj = json_decode($out);print $obj;
POST 数据发送
$url = "http://www.xxxx.com?user=111";$post_data = "somedata";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch , CURLOPT_POST , 1 ) ;curl_setopt($ch , CURLOPT_POSTFIELDS , $post_data ) ;$out = curl_exec($ch);curl_close($ch);$obj = json_decode($out);print $obj;
http://php.net/manual/zh/function.curl-setopt.php 可以去文档中去 找寻更多的选项。
有一次还用到 这两个 选项
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
反正在 POST不到数据的时候,要多看看选项。 POST 数据接收
$post_data = file_get_contents("php://input");$post_data = trim($post_data);print $post_data;