PHP code example of nsp-team / simple-http

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

    

nsp-team / simple-http example snippets



Yurun\Util\YurunHttp\Http\Psr7\UploadedFile;
use Yurun\Util\YurunHttp\Http\Psr7\Consts\MediaType;

$response = \NspTeam\HttpClient::create()->get('https://www.baidu.com');

$response = \NspTeam\HttpClient::create()
    ->withHeaders([
    'content-type' => 'application/json'
    ])
    // 同时支持POST参数、上传文件
    ->withContent([
    'lang' => 'php',
    'ver'  => 'any',
    'file' => new \Yurun\Util\YurunHttp\Http\Psr7\UploadedFile('1.txt', MediaType::TEXT_PLAIN, __FILE__),
    ])
    ->post('https://www.baidu.com');


$url = 'https://www.baidu.com'
$response = \NspTeam\HttpClient::create()->download(__DIR__ . '/save.*', $url); // 如果文件名设为save.*,.* 则代表自动识别扩展名