thevenrex / curlx
用 PHP 编写的 HTTP 基础库
0.0.5
2024-08-21 03:25 UTC
This package is auto-updated.
Last update: 2024-09-21 03:40:24 UTC
README
CurlX 是一个用 PHP 为人类编写的 HTTP 基础库,无依赖,与 PHP 8.2+ 兼容。
CurlX 允许您发送 GET、POST、PUT、DELETE 以及更多 HTTP 方法。您可以添加头部、表单数据、JSON 数据和简单的数组参数,并以相同的方式访问响应数据。您可以添加带有 PROXY 的 HTTP TUNNEL,如 LUMINATI、APIFY、IPVANISH 服务器旋转。
GET、POST 和自定义语法
# GET $CurlX->get("https://api.myip.com/"); # POST $CurlX->post("https://api.myip.com/", "my_form_id=test&hello=mom"); # CUSTOM $CurlX->custom("https://api.myip.com/", "HEAD"); $CurlX->run();
HTTP TUNNEL 语法
# PROXY (http/s, socks4, socks5) $server = [ "method" => "tunnel", "server" => "47.254.145.99:3128" ]; # LIMINATI valid syntax example $session => mt_rand(); $server = [ "method" => "custom", "server" = "http://zproxy.lum-superproxy.io:22225", "auth" => "lum-customer-hl_876f552a-zone-static-route_err-pass_dyn-country-RU-session-$session:my_ultra_secret_password" ]; # APIFY valid syntax example $server = [ "method" => "custom", "server" = "http://proxy.apify.com:8000", "auth" => "auto:my_ultra_secret_password" ]; # IPVANISH valid syntax example $server = [ "method" => "CUSTOM", "server" => "akl-c12.ipvanish.com:1080", "auth" => "my_zone_customer_id:my_zone_customer_password" ];
GET 语法
# Simple GET $test0 = $CurlX->get("http://httpbin.org/get"); # GET with Custom Headers $headers = array( "Host: api.myip.com", "my-custom-header: my-header-value" ); $test1 = $CurlX->get("http://httpbin.org/get", $headers); # GET with Headers and Cookie File $cookie = uniqid(); $test2 = $CurlX->get("http://httpbin.org/get", $headers, $cookie); #GET with Headers, Cookie and Proxy Tunnel $server = [ "method" => "tunnel", "server" => "47.254.145.99:3128" ]; $test3 = $CurlX->get("http://httpbin.org/get", $headers, $cookie, $server); # After all requests were complete, you can delete the cookie file, Only when you use the $cookie parameter. $CurlX->deleteCookie(); # Response status of the request var_dump($test3->isSuccess()); // bool(true) # Status code of the request var_dump($test3->getStatusCode()); // int(200) # Content type of the request var_dump($test3->getHeaders()["response"]["content-type"]); // string(24) "text/html; charset=UTF-8" # Body response of the request var_dump($test3->getBody()); // string(51) "{...}"
POST 语法
#Simple POST with NULL data $test0 = $CurlX->post("http://httpbin.org/post"); #POST with Data-form and Custom Headers $headers = array( "Host: httpbin.org", "my-custom-header: my-header-value" ); $test1 = $CurlX->post("http://httpbin.org/post", "test_ID=666&hello=mom", $headers); #POST with Json-Data and Custom Headers $data = array( "hello" => "mom", "key" => "value" ); $test2 = $CurlX->post("http://httpbin.org/post", $data, $headers); #POST with Custom-Data, Custom Headers, and Cookie $cookie = uniqid(); $test3 = $CurlX->post("http://httpbin.org/post", $data, $headers, $cookie); #POST with Json-Data, Custom Headers, Cookie and Proxy Tunnel $server = [ "method" => "tunnel", "server" => "47.254.145.99:3128" ]; $test4 = $CurlX->post("http://httpbin.org/post", $data, $headers, $cookie, $server); #After all requests were complete, you can delete the cookie file, Only when you use the $cookie parameter. $CurlX->deleteCookie(); # Response status of the request var_dump($test3->isSuccess()); // bool(true) # Status code of the request var_dump($test4->getStatusCode()); // int(200) # Content type of the request var_dump($test4->getHeaders()["response"]["content-type"]); // string(24) "..." # Body response of the request var_dump($test4->getBody()); // string(51) "{...}"
其他功能
// Set a custom option to current CURL structure $CurlX->setOpt([CURLOPT_HTTPAUTH => CURLAUTH_BEARER]); /** * Show all data process|errors of the request * * debug(): now supports cli and json print * * Recommended for develop work space */ $CurlX->debug();
更多?
- 更多示例在 examples 目录中。
特性
- 国际域名和 URL
- 自定义隧道 HTTP 带代理、Socks、Luminati、Apify、IpVanish
- 重新利用 Cookie 数据
- 自定义 HTTP 方法
安装
从 GitHub 安装源代码
要安装源代码
$ git clone https://github.com/devblack/curlx.git
$ cd curlx
$ composer install
并在您的脚本中包含它
require_once __DIR__ . '/vendor/autoload.php';
use Thevenrex\Curlx\CurlX;
$CurlX = new CurlX();
使用 composer 安装
使用 composer 包管理器安装库 [php]
$ composer require thevenrexoff/curlx
贡献
- 查找开放的问题或为功能请求或错误打开新问题
- 在 GitHub 上 仓库 进行分支,以开始对
master
分支(或从中分支)进行更改 - 编写一个测试,以证明错误已被修复或功能按预期工作
- 发送拉取请求,并烦扰我,直到合并