GET(URL 传参数)
//初始化
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "XXXX");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//执行并获取文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
POST(post参数需要设置)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'XXXXXXXXXX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, '可以是数组');
$output = curl_exec($ch);
curl_close($ch);
网友评论