PHP CURL GET/POST简单使用

GET

$url = "http://localhost:8080/ali_sp/getSystemOauthToken?auth_code=".$_REQUEST['auth_code'];

//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行命令
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl);
//显示获得的数据
echo $data;

POST

$url = "http://localhost:8080/ali_sp/getSystemOauthToken";
$post_data = "auth_code=".$_REQUEST['auth_code'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//true返回为存储变量,不直接输出
curl_setopt($ch, CURLOPT_POST, 1);//执行http post操作
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$res = curl_exec($ch);
curl_close($ch);
print_r($res);

猜你喜欢

转载自blog.csdn.net/u012663254/article/details/80742353