PHP code example of zatxm / yrequest

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

    

zatxm / yrequest example snippets


    
    use Zatxm\YRequest\Curl;

    $curl = Curl::boot();
    $url = 'http://xxxx';
    $params = ['a'=>'aaa', 'b'=>'bbb'];
    $headers = ['a'=>'aaa', 'b'=>'bbb'];
    $cookies = ['a'=>'aaa', 'b'=>'bbb'];
    // option目前支持选项如下:
    // async=1异步
    // nobody=1不返回响应内容,cmdopt不支持此配置
    // resheader=1返回响应头部,cmdopt一直返回
    // rescookie=1返回响应cookie,cmdopt一直返回
    // timeout=60设置通信超时时间秒数,默认30
    // followlocation=1是否重定向,cmdopt不支持此配置
    // cmdopt=curl_edge101支持原生模拟浏览器TLS/JA3指纹的验证
    // source=[]原生curl_multi_setopt配置,可能会被上面设置覆盖
    $option = ['nobody'=>1, 'resheader'=>1];
    $res = $curl->url($url)
        ->method('POST')
        ->params($params)
        ->header($headers)
        ->cookie($cookies)
        ->option($option)
        ->go();
    if (CurlErr::is($res)) {
        print_r($res);
        exit;
    }
    print_r($res);
  

    
    use Zatxm\YRequest\CurlOfSession;

    $curl = CurlOfSession::boot();
    $url1 = 'http://xxxx';
    $params = ['a'=>'aaa', 'b'=>'bbb'];
    $headers = ['a'=>'aaa', 'b'=>'bbb'];
    $cookies = ['a'=>'aaa', 'b'=>'bbb'];
    $option = ['nobody'=>1, 'resheader'=>1];
    $res = $curl->url($url)
        ->method('POST')
        ->params($params)
        ->header($headers)
        ->cookie($cookies)
        ->option($option)
        ->go();
    if (CurlErr::is($res)) {
        print_r($res);
        exit;
    }
    print_r($res);
    $url2 = 'http://xxxx';
    $params = ['a'=>'aaa', 'b'=>'bbb'];
    $headers = ['a'=>'aaa', 'b'=>'bbb'];
    $cookies = ['a'=>'aaa', 'b'=>'bbb'];
    $option = ['nobody'=>1, 'resheader'=>1];
    $res = $curl->url($url)
        ->method('POST')
        ->params($params)
        ->header($headers)
        ->cookie($cookies)
        ->option($option)
        ->go();
    if (CurlErr::is($res)) {
        print_r($res);
        exit;
    }
    print_r($res);
  

    
    use Zatxm\YRequest\Murl;

    $multiOtion = [
        [
            'url' => 'https://xx.xx.xx',
            'params' => ['a'=>'aaa', 'b'=>'bbb'],
            'header' => ['a'=>'aaa', 'b'=>'bbb'],
            'cookie' => ['a'=>'aaa', 'b'=>'bbb'],
            'option' => ['nobody'=>1, 'resheader'=>1]
        ],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx'],
        ['url' => 'https://xx.xx.xx']
    ];
    $murl = Murl::boot();
    $res = $murl->multiOtion($multiOtion)->go();
    print_r($res);