Maison > php教程 > php手册 > le corps du texte

php curl 相关知识

WBOY
Libérer: 2016-06-13 11:29:26
original
843 Les gens l'ont consulté

    

<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>);
Copier après la connexion

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal