PHP中使用CURL(一)

执行流程:

curl_init()初始化 -> curl_setopt()设置变量 -> curl_exec()获取结果 -> curl_close()释放句柄

Get:

$ch = curl_init();
curl_setopt($ch, curlOPT_URL, "http://www.baidu.com");
curl_setopt($ch, curlOPT_RETURNTRANSFER, 1);
curl_setopt($ch, curlOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);

Post:

$url = "http://www.yudis.cn/callback.php";
$data = ["username" => "uname"];
$ch = curl_init();
curl_setopt($ch, curlOPT_URL, $url);
curl_setopt($ch, curlOPT_RETURNTRANSFER, 1);
curl_setopt($ch, curlOPT_POST, 1);
curl_setopt($ch, curlOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
posted @ 2016-06-21 10:54  yudis  阅读(227)  评论(0编辑  收藏  举报