nichin79/curl-php

该包最新版本(v1.0.0)没有提供许可证信息。

PHP的基本curl类

v1.0.0 2023-10-26 22:47 UTC

This package is auto-updated.

Last update: 2024-09-27 00:51:35 UTC


README

包含两个类

  • Curl
  • BasicCurl

BasicCurl 扩展了Curl类,并会自动使用curlopt的ssl_verifypeer和returntransfer。此外,它还会自动执行curl。

  • ssl_verifypeer
  • returntransfer。此外,它还会自动执行curl。

如果设置了curlopt_returntransfer,可以通过$curl->getResponse()获取响应。

use Nichin79\Curl\BasicCurl;use Nichin79\Curl\Curl;

设置curl的参数/选项可以通过两种方式完成

选项1

$data = [
  'url' => 'https://reqbin.com/echo',
  'method' => 'GET', // Method will automatically be set to GET if not specified
  'headers' => [],
  'options' => [
  'SSL_VERIFYPEER' => false
  ]
];

选项2

$data = [
  'curlopt_url' => 'https://reqbin.com/echo',
  'curlopt_ssl_verifypeer' => false,
];

使用方法

$curl = new Curl($data);

// execute the initiated curl and return the response
$curl->exec();

echo "\r\n";
echo "http status code: " . $curl->httpcode;

设置url、方法、头和数据的设置是可选的,也可以在选项数组中设置。