定制 jyoungblood/http-request 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jyoungblood/http-request

最新稳定版本:1.2.0

Composer 安装命令:

composer require jyoungblood/http-request

包简介

PHP functions to handle sending and receiving HTTP requests with CURL.

README 文档

README

HTTP Request

Vanilla PHP functions to handle sending and receiving HTTP requests with CURL. This is a set of thin abstractions over a typical CURL request workflow with configurable options.

Installation

Easy install with composer:

composer require jyoungblood/http-request
use VPHP\http;
require __DIR__ . '/vendor/autoload.php';

Usage

http::request($url, $parameters)

Makes an http request to a given url, sending an array of data and returning the raw response.

$api_data = http::request('https://external-api.com/v3/example-response', [
  'method' => 'POST', // optional, GET by default, GET and POST supported currently
  'json_decode' => true, // optional, returns an expected JSON response as a PHP array
  'debug' => true, // optional, returns all request information from curl_getinfo()
  'headers' => [ // optional, define any custom header
    'Cache-Control' => 'no-cache',
    'Content-Type' => 'application/json',
  ],
  'data' => [ // optional, will be submitted as querystring (GET) or FormData (POST)
    'user_id' => 581146,
    'api_key' => '696719xvckvzxspigh24y1e-b'
  ]
]);

http::get($url, $parameters)

Alias to http::request using the default GET method.

$api_data = http::get('https://external-api.com/v3/example-response', [
  'data' => [
    'user_id' => 581146,
    'api_key' => '696719xvckvzxspigh24y1e-b'
  ]
]);

Everything in the the 'data' array will be submitted as a querystring. For example:

https://external-api.com/v3/example-response?user_id=581146&api_key=696719xvckvzxspigh24y1e-b

http::post($url, $parameters)

Alias to http::request using the POST method.

$api_data = http::post('https://external-api.com/v3/example-response', [
  'data' => [
    'user_id' => 581146,
    'api_key' => '696719xvckvzxspigh24y1e-b'
  ]
]);

Everything in the 'data' array will be submitted as FormData.

http::json($url, $parameters)

Alias to http::request() using the json_decode parameter (returns an expected JSON response as a PHP array)

$api_data = http::json('https://external-api.com/v3/example-response', [
  'data' => [
    'user_id' => 581146,
    'api_key' => '696719xvckvzxspigh24y1e-b'
  ]
]);

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-22