Home > Backend Development > PHP Tutorial > php curl related knowledge_PHP tutorial

php curl related knowledge_PHP tutorial

WBOY
Release: 2016-07-20 11:13:37
Original
875 people have browsed it

    

<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>);
Copy after login

 

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(...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template