get 数据请求
立即学习“PHP免费学习笔记(深入)”;
<span style="font-size:18px;">$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;</span>
立即学习“PHP免费学习笔记(深入)”;
POST 数据发送
立即学习“PHP免费学习笔记(深入)”;
<span style="font-size:18px;">$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;</span>
立即学习“PHP免费学习笔记(深入)”;
http://php.net/manual/zh/function.curl-setopt.php 可以去文档中去 找寻更多的选项。
有一次还用到 这两个 选项
<span style="font-size:18px;"> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);</span>
立即学习“PHP免费学习笔记(深入)”;
POST 数据接收
<span style="font-size:18px;">$post_data = file_get_contents("php://input");$post_data = trim($post_data);print $post_data;</span>
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号