zms/request

curl请求工具

v1.0.2 2025-03-14 07:06 UTC

This package is not auto-updated.

Last update: 2025-03-28 07:24:38 UTC


README

网络请求简单封装

  • 支持POST,GET请求
  • 支持发送cookie
  • 支持设置header

代码示例


use Zms\Request\Http;
use Zms\Request\Result;
/**
 * @var Result $result
 */
$result = Http::instance(Http::CURL)
    ->setMethod('POST')
    ->setData(['name' => '张三'])
    ->setCookies([
        'mobile' => '10086',
        'addres' => '四川省成都市'
    ])
    ->setHeaders([
        'user-agent' => 'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0'
    ])
    ->execute('https://www.baidu.cn', [
        'sex' => '12', 'info' => [1, 2, 3]
    ]);
  • Http::instance(Http::CURL)参数可选Http::CURL和Http::SWOOLE,
  • 可以设置常量ZMS_REQUEST_DRIVER来默认指定底层驱动
  • 当选择Http::SWOOLE时需要在swoole协程环境中执行
  • 已知在cygwin环境下不可用(含swoole-cli)