Heim > Backend-Entwicklung > PHP-Tutorial > php curl 相关知识_PHP教程

php curl 相关知识_PHP教程

WBOY
Freigeben: 2016-07-20 11:13:37
Original
875 Leute haben es durchsucht

    

<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>);
Nach dem Login kopieren

 

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(...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage