PHP curl 详解

时间:2022-04-29
本文章向大家介绍PHP curl 详解,主要内容包括post、https、htpasswd、参考链接、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

本文详细记录了 PHP 使用 curl 遇到的问题。

官方文档:http://php.net/manual/zh/book.curl.php

设置网址

curl_setopt($ch, CURLOPT_URL, $url);

post

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data)

https

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);

// 设置 CA 根证书路径

curl_setopt($ch, CURLOPT_CAINFO, $value);

// 检查证书域名

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value);

// 设置私钥路径

curl_setopt($ch, CURLOPT_SSLKEY, $value);

// 设置公钥路径

curl_setopt($ch, CURLOPT_SSLCERT, $value);

htpasswd

curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);

参考链接