jonathrg/send 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jonathrg/send

Composer 安装命令:

composer require jonathrg/send

包简介

A single function, send(), which performs one HTTP request.

README 文档

README

Send provides a single function, send(), which performs one HTTP request.

Install

composer require jonathrg/send

Usage

Provide send() with an array defining your request to perform that request. The result is returned as a string.

Here is the simplest possible use-case, which retrieves the example.org frontpage and prints it. You can test this by serving the repo and going to Send/examples/example.php on localhost.

<?php
require_once __DIR__.'path/to/vendor/autoload.php';

use function Send\send;

echo(send(['url' => 'http://example.org']));

Get stuff

// Get the webpage for example.org and send some headers

$response = send([
    'url' => 'http://example.org',
    'headers' => $headers
]);

Post stuff

// Post something to the webpage for example.org

$response = send([
    'url' => 'http://example.org',
    'method' => 'POST',
    'data' => $data
]);

Put and delete stuff

You can of course also put stuff and delete stuff by setting 'method' to 'DELETE' or 'PUT'.

Defining the request

send() takes one argument, which contains the data about your request. The only required field for the this argument is 'url' (which should be a valid URL). 'method' must be one of 'GET', 'POST', 'PUT' and 'DELETE', and is 'GET' by default. If you are sending a POST request, you should also populate the 'data' field with the POST fields.

If you want to, you can use the options accepted by curl_setopt. For convenience, the array keys can also be one of these "translations", and it will have the same effect:

$CURL_TRANSLATION = [
    'url'                => CURLOPT_URL,
    'data'               => CURLOPT_POSTFIELDS,
    'post'               => CURLOPT_POST,
    'get'                => CURLOPT_HTTPGET,
    'put'                => CURLOPT_PUT,
    'method'             => CURLOPT_CUSTOMREQUEST,
    'timeout'            => CURLOPT_TIMEOUT,
    'timeout_ms'         => CURLOPT_TIMEOUT_MS,
    'connect_timeout'    => CURLOPT_CONNECTTIMEOUT,
    'connect_timeout_ms' => CURLOPT_CONNECTTIMEOUT_MS,
    'headers'            => CURLOPT_HTTPHEADER,
    'user_agent'         => CURLOPT_USERAGENT,
    'file'               => CURLOPT_INFILE,
    'file_size'          => CURLOPT_INFILESIZE,
    'no_body'            => CURLOPT_NOBODY,
    'fetch_headers'      => CURLOPT_HEADER
];

Optional error handling

If you want, you can provide a second argument which will contain a string with the error message returned by cURL:

$error = "";
$response = send($request, $error);
if ($error) {
    echo ($error);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固