测试域名:www.test.com
文件:curl.php
<?php
//初始化
//GET方式
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "http://www.test.com/data.php?test=123");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //取消ssl验证,访问https
//执行并获取HTML文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
//打印获得的数据
print_r($output);
//POST方式
//初始化
//POST方式
$data_string['a'] = 'test1';
$data_string['b'] = 'test2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.test.com/data.php?test=123');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //取消ssl验证,访问https
//执行并获取接口传的内容
$ret = curl_exec($ch);
curl_close($ch);
print_r($ret);
|