标签:style blog http color os ar 文件 sp div
CURL学习:
文章目录
get提交,直接写到url上。
$ch=curl_init();//初始化一个CURL对话; curl_setopt($ch, CURLOPT_URL, "http://localhost/wish/test/file2.php?t=1&p=2"); curl_setopt($ch, CURLOPT_HEADER, 0); // 抓取URL并把它传递给浏览器 curl_exec($ch); // 关闭cURL资源,并且释放系统资源 curl_close($ch);
post提交
$ch=curl_init();//初始化一个CURL对话; $data=array( ‘name‘=>‘xie‘, ‘password‘=>‘123456‘, ); curl_setopt($ch, CURLOPT_URL, "http://localhost/wish/test/file2.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); // 抓取URL并把它传递给浏览器 curl_exec($ch); // 关闭cURL资源,并且释放系统资源 curl_close($ch);
http://localhost/wish/test/file2.php 对应文件代码:
$post = array( ‘name‘=>‘xyt‘, "excel"=>"@1.txt",//这里是要上传的文件,key与后台处理文件对应 ); echo "start:----------\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost/wish/test/file2.php"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS,$post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 0); $a=curl_exec($ch); echo $a; curl_close($ch);
php curl模拟 get,post提交,上传文件,下载文件
标签:style blog http color os ar 文件 sp div
原文地址:http://www.cnblogs.com/canbefree/p/4013427.html