folour/oxide

基于cURL的简单轻量级PHP 7.1 HTTP客户端

v1.0.1 2017-06-16 00:39 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:00:00 UTC


README

Scrutinizer Code Quality downloads license

基于cURL的简单轻量级PHP 7.1 HTTP客户端

要求

Oxide需要PHP 7.1和php-curl扩展

安装

    composer require folour/oxide

基本用法

    <?php declare(strict_types=1);
    
    use Folour\Oxide\Oxide;
    
    $oxide = new Oxide();
    $response = $oxide->get('https://google.com', ['q' => 'php 7.1']);
    
    //get response body
    echo $response->body(); //Or echo $response;
    //get response code
    echo $response->code();
    //get response headers
    var_dump($response->headers());

配置

    <?php declare(strict_types=1);
    
    use Folour\Oxide\Oxide;
    
    $oxide = new Oxide();
    $oxide
        ->setHeaders([
            'Referer' => 'http://local.dev'
        ])
        ->setCookies([
            'cookie' => 'value'
        ])
        ->setProxy('user:pwd@127.0.0.1:8080');
    
    $response = $oxide->post('http://httpbin.org/post', ['test']);

更多HTTP请求方法

    <?php declare(strict_types=1);
    
    use Folour\Oxide\Oxide;
    
    $oxide = new Oxide();
    
    echo $oxide->get('http://httpbin.org/get', ['key' => 'value']);
    echo $oxide->head('http://httpbin.org/get', ['key' => 'value']);
    echo $oxide->post('http://httpbin.org/post', ['key' => 'value']);
    echo $oxide->put('http://httpbin.org/put', ['key' => 'value']);
    echo $oxide->delete('http://httpbin.org/delete', ['key' => 'value']);