PHP code example of ezijing / http-request-utils

1. Go to this page and download the library: Download ezijing/http-request-utils 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/ */

    

ezijing / http-request-utils example snippets




declare(strict_types=1);

namespace HyperfTest\Cases;

use Hyperf\HttpRequest\BaseRequest;
use Hyperf\HttpRequest\Request;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 * @coversNothing
 */
class RequestTest extends TestCase
{
    protected $request;

    protected function setUp(): void
    {
        $this->request = make(Request::class);
    }

    public function testRequestSend()
    {
        $url = 'https://XXX/growth_api/v1/lottery_config/get';
        $data = [
            'aid' => '6587',
            'uuid' => '7039128193925088782',
        ];
        $cookies = [
            'a' => 1,
        ];
        $headers = ['response_str' => true];
        $result = $this->request
            ->getInstance(BaseRequest::GET_METHOD)
            ->withUrl($url)
            ->withRequestData($data)
            ->withCookies($cookies)
            ->withHeaders($headers)
            ->request();

        $this->assertIsArray($result);
        print_r($result);
    }
}