1,Curl 模拟GET请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.nettuts.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
2,Curl 模拟POST 请求
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$out_put = curl_exec($ch);
curl_close($ch);
3,Curl 模拟put请求
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "put");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out_put = curl_exec($ch);
curl_close($ch);
4,Curl 上传文件
header('content-type:text/html;charset=utf8');
$url = "http://".$_SERVER['HTTP_HOST']."/index.php?a=upfile";
$post_data = array(
'type' => 'attach',
'file' => new \CURLFile(realpath('a.txt'))
);
$ch = curl_init($url);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch , CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
echo $output;