首頁 > 後端開發 > php教程 > php curl 相关知识_PHP教程

php curl 相关知识_PHP教程

WBOY
發布: 2016-07-20 11:13:37
原創
879 人瀏覽過

    

<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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板