首页 > 后端开发 > php教程 > php curl 相关知识_PHP教程

php curl 相关知识_PHP教程

WBOY
发布: 2016-07-20 11:13:37
原创
875 人浏览过

    

<span $ch</span> =<span  curl_init();

</span><span #</span><span  设定url和把结果返回,是否返回头部</span>
curl_setopt(<span $ch</span>, CURLOPT_URL, 'http://www.baidu.com/'<span );
curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span );
curl_setopt(</span><span $this</span>->ch, CURLOPT_HEADER, 1<span );

</span><span #</span><span  cookie文件设定</span>
curl_setopt(<span $this</span>->ch, CURLOPT_COOKIEJAR,  <span $cookie_file</span><span );
curl_setopt(</span><span $this</span>->ch, CURLOPT_COOKIEFILE, <span $cookie_file</span><span );

</span><span #</span><span  额外头部</span>
curl_setopt(<span $this</span>->ch, CURLOPT_HTTPHEADER, <span array</span>('User-Agent: Mozilla/5.0'<span ));

</span><span #</span><span  设定post</span>
curl_setopt(<span $ch</span>, CURLOPT_POST, 1<span );
curl_setopt(</span><span $ch</span>, CURLOPT_POSTFIELDS, <span $poststring</span><span );

</span><span #</span><span  连接、执行过期时间</span>
curl_setopt(<span $this</span>->ch, CURLOPT_CONNECTTIMEOUT, 5<span );
curl_setopt(</span><span $this</span>->ch, CURLOPT_TIMEOUT, 5<span );

</span><span #</span><span  是否跟随301 302</span>
curl_setopt(<span $this</span>->ch, CURLOPT_FOLLOWLOCATION, 1<span );
curl_setopt(</span><span $this</span>->ch, CURLOPT_MAXREDIRS, 10<span );

</span><span #</span><span  refer</span>
curl_setopt(<span $this</span>->ch, CURLOPT_REFERER, <span $refer</span><span );

</span><span #</span><span  http版本和端口重用设置</span>
curl_setopt(<span $this</span>->ch, CURLOPT_HTTP_VERSION,<span  CURL_HTTP_VERSION_1_1);
curl_setopt(</span><span $this</span>->ch, CURLOPT_FORBID_REUSE, 1<span );

</span><span #</span><span  支持https</span>
curl_setopt(<span $this</span>->ch, CURLOPT_SSL_VERIFYPEER, 0<span );
curl_setopt(</span><span $this</span>->ch, CURLOPT_SSL_VERIFYHOST, 0<span );

</span><span #</span><span  执行</span>
curl_setopt(<span $this</span>->ch, CURLOPT_NOSIGNAL, 1<span );
</span><span $response</span> = curl_exec(<span $ch</span><span );
</span><span if</span>(curl_errno(<span $ch</span><span )){
    curl_error(</span><span $ch</span><span );
    </span><span exit</span><span ();
}
curl_close(</span><span $ch</span>);
登录后复制

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440347.htmlTechArticle= curl_setopt( , CURLOPT_URL, 'http://www.baidu.com/' , CURLOPT_RETURNTRANSFER, 1 -ch, CURLOPT_HEADER, 1 curl_setopt( -ch, CURLOPT_COOKIEJAR, -ch, CURLOPT_COOKIEFILE, curl_setopt(...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板