thinknet/request

简单的 HTTP 请求

1.1 2016-10-31 09:10 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:17:44 UTC


README

laravel 的 php http 请求

支持

  • HTTP 方法:GET、POST、PUT、DELETE

要求

  • PHP 5.6.0
  • Laravel 5.3
  • guzzle 6.0

Composer

此插件在 Packagist 上。

https://packagist.org.cn/packages/thinknet/request

使用 composer require thinknet/request 安装最新版本

要获取主题的最新版本,只需在 composer.json 文件中引入它。

    "thinknet/request": "dev-master"

然后您需要运行 composer install 以下载它并更新自动加载器。

主题安装完成后,您需要将服务提供者注册到应用程序中。打开 config/app.php 并找到 providers 键。

'providers' => array(

    'Thinknet\Request\RequestServiceProvider'

)

您可以在 config/app.php 文件的 aliases 键中注册外观。

'aliases' => array(

    'ThinknetService' => 'Thinknet\Request\Service'

)

您可以在 .env 文件上设置 URL

SERVICE_BASE_URL=http://www.example.com

用法

ThinknetService 请求的 API 格式。

use ThinknetService;

class ServiceController extends Controller
{
    protected $service;

    public function __construct(Service $service)
    {
        $this->service = $service;
    }
}

主要方法

// get : Return this
public function getService()
{
    $this->service->get(url, param);
}

// post : Return this
public function postService()
{
    $this->service->post(url, param);
}

// put : Return this
public function putService()
{
    $this->service->put(url, param);
}

// delete : Return this
public function deleteService()
{
    $this->service->delete(url, param);
}

其他方法

// getResult : Return Json Obj OR Null
    $this->service->getResult();

// call : Return this
    $this->service->call($url, $method)

// isSuccess : Return Boolean
    $this->service->isSuccess();

// getHttpCode : Return int
    $this->service->getHttpCode();

// setHeader : Return Void
    $this->service->setHeader(key, value);

// addHeader : Return Void
    $this->service->SetHeader(array $params);

// setParameters : Return Void
    $this->service->setParameters(array $params);
    
// setbody : Return Void
    $this->service->setBody(params)
    
// basicAuth : Return Void
    $this->service->basicAuth(username, password);

// getError : Return Json Obj
    $this->service->getError();

许可证

MIT 许可证 (MIT)