lucasarend/http-fox

此包是使用curl的基础

v1.0.7 2024-04-08 20:08 UTC

This package is auto-updated.

Last update: 2024-09-19 18:29:22 UTC


README

关于包

嘿,这是我的第一个包,我还在学习中。请随意提出改进建议

安装

路由器通过Composer可用

"lucasarend/http-fox": "^1.0"

或者运行

composer require lucasarend/http-fox

文档

多爬虫

如果你打算用于多个爬虫或需要cookie的并发请求,请在.env文件中设置此选项。

HTTP_MULTI_CRAWLER=true

创建类

<?php

use LucasArend\HttpFox\HttpFox;

$http = new HttpFox();

简单获取页面

$http->getURL('https://www.blogger.com/about/?hl=pt-br');
//Write Page Return
echo $http->response;

简单POST

$postData = 'name=Lucas';
$http->sendPost('https://www.blogger.com/about/?hl=pt-br',$postData);
//Write Page Return
echo $http->response;

简单PUT

$http->sendPUT('https://www.blogger.com/about/?post=1','putData');

简单DELETE

$http->sendDELETE('https://www.blogger.com/about/?post=1');
//Withe Post Data
$http->sendDELETE('https://www.blogger.com/about/?post=1','postData');

自定义头

$http->setHeader('header','value');
//Use array header
$http->setHeaders(['Content-Type: application/json','Accept: application/json']);

工具

获取远程文件大小

支持的单位MB KB GB 默认返回字节

$size = $http->get_file_size('https://cdn.britannica.com/79/232779-004-9EBC7CB8/German-Shepherd-dog-Alsatian.jpg?s=1500x700&q=85','MB');

禁用SSL检查

此选项禁用了对网站SSL证书的检查。

$http->disableSSL();

设置请求超时

覆盖php.ini文件中设置的默认超时值。

$http->setTimeOut(30);

在请求中使用PFX文件

支持P12类型,总是传递文件的完整路径。

$http->setPFX('path','pass');

在请求中使用PEM证书

总是传递文件的完整路径。

//With password
$http->setPEM('path','pass');
//Not use password
$http->setPEM('path');

自定义用户代理

当你不使用此功能时,它将始终使用库内部配置的Firefox版本。

$http->setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0');

代理和调试

设置代理

如果你需要使用代理服务或查看你的请求,请使用此功能。用户名和密码不是必需的。

$http->setProxy('Host',Port,'User','Password');

调试

调试请求

要调试请求,你需要一个程序将这些请求作为代理服务器插入,我喜欢使用Fiddler。
简单调试例程示例

use LucasArend\HttpFox\HttpFox;

$http = new HttpFox();

$http->setProxy();//setProxy use default fiddler config

$http->getURL('https://www.blogger.com/about/?hl=pt-br');

//Write Page Return
echo $http->response;

响应头

$httpFox = new HttpFox();
$httpFox->enableResponseHeader(); //Enable response headers

$httpFox->enableResponseHeader(false); // Disable response headers

cURL详细

//Enable Verbose
$http->enableVerbose();
//Your request
$http->get('www.mysite.com.br');
//Get Verbose
$verbose = $http->getVerbose();

如果需要禁用详细模式

$http->disableVerbose();

许可

MIT许可证(MIT)。请参阅许可文件以获取更多信息。