欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP中curl的使用

程序员文章站 2023-02-20 15:32:50
curl_init() 返回一个 cURL handle curl_setopt() 为cURL handle设置参数,格式为 CURLOPT_XXX 常用参数: CURLOPT_URL:url CURLOPT_REFERER:Referer提交的页面 CURLOPT_POST:是否是post请求 ......

curl_init()

返回一个 curl handle


curl_setopt()

为curl handle设置参数,格式为 curlopt_xxx
常用参数:

  • curlopt_url:url

  • curlopt_referer:referer提交的页面

  • curlopt_post:是否是post请求

  • curlopt_timeout:超时时间

  • curlopt_httpheader:head请求数据

  • curlopt_header:

  • curlopt_ssl_verifypeer:false to stop curl from verifying the peer's certificate. alternate certificates to verify against can be specified with the curlopt_cainfo option or a certificate directory can be specified with the curlopt_capath option.

  • curlopt_ssl_verifyhost:1 to check the existence of a common name in the ssl peer certificate. 2 to check the existence of a common name and also verify that it matches the hostname provided. 0 to not check the names. in production environments the value of this option should be kept at 2 (default value).

  • curlopt_returntransfer:true to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.

  • curlopt_postfields:post提交数据


curl_exec()

执行请求,如果设置了 curlopt_returntransfer,成功会返回结果,失败返回false。


curl_close()

关闭