PHP code example of zodream / http

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

    

zodream / http example snippets



use Zodream\Http\Http;



(new Http('https://zodream.cn'))->get();



(new Http())->url('https://zodream.cn', [
    'page' => 1
])->get();



(new Http('https://zodream.cn'))->maps([
    'page' => 1
])->text();



(new Http())->url('https://zodream.cn', [
    'keywords'
])->maps([
    'page' => 1,     // 这是使用默认值
    '#url'           // 如果没有会报错
])->parameters([
    'url' => 'aaaa',
    'keywords' => 'q',
    'aa' => 'bb'        // 这个并不会传递过去
])->encode(Http::JSON)->decode(Http::Json)->decode(function($data) {
    $data['a'] = $data['data'];
    return $data;
})->text();



[
   'code' => 200,
   'data' => 'a',
   'a'    => 'a' 
]



$data = Http::getMapParameters([
    '#goods_id',              // # 必须有值 否则报错
    'a:f' => [                // 如果 f 有值 传给 a 即 a => 2,如果无值, 进行子匹配  a => [e => 11]
        '#e'
    ],
    [              // 多个里面匹配至少一个
        'b',
        'c',
        'd'
    ],
    'g' => 1                 // 可以设置默认值, 数组不是默认值
], [
    'goods_id' => 1,
    'f' => 2,
    'c' => 4,
    'd' => 7,
    'e' => 11
]);