PHP code example of exewen / http

1. Go to this page and download the library: Download exewen/http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

exewen / http example snippets


!defined('BASE_PATH_PKG') && define('BASE_PATH_PKG', dirname(__DIR__, 1));

# 初始化 DI
$app      = ApplicationContext::getContainer();
$app->setProviders([LoggerProvider::class,LoggerProvider::class]);
$this->app = $app;
/** @var HttpClientInterface $http */
$http = $this->app->get(HttpClientInterface::class);

# get
$response = $http->get('nacos', '/nacos/v1/cs/configs', [
    'dataId' => $this->dataId,
    'group' => $this->group,
    'tenant' => $this->namespaceId,
]);

# post
$response = $http->post('nacos', '/nacos/v1/ns/instance', [
    'namespaceId' => $this->namespaceId,
    'serviceName' => $this->serviceName,
    'groupName' => $this->group,
    'ip' => '10.0.2.143',
    'port' => 8081,
    'metadata' => json_encode([
        'ver' => "1.0.0"
    ], JSON_UNESCAPED_UNICODE),
]);