Skip to content

Curl Http Client Builder, Support GET, POST, PUT, DELETE Method

License

Notifications You must be signed in to change notification settings

zeroibc/httpbuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Curl Http Client

Usage

Http Client Support Http Method : GET, POST, PUT , DELETE

构建 HttpClient

protected $client ;
function __construct()
{
    $this->client = HttpClientBuilder::create()->build();
}

GET Request

$data = [
    'uri'=>'https://www.baidu.com'
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->setHeaders('X-HTTP-Method-Override:GET')
    ->setHeaders('Request_id: Ethan')
    ->setTimeout(10)
    ->Get($data);

POST Request

$data = [
    'uri'=>'https://www.baidu.com',
    'params'=> [
        'user'=>ethan
     ]
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->Post($data);

PUT 、DELETE Request

$data = [
    'uri'=>'https://www.baidu.com',
    'params'=> [
        'user'=>ethan
     ]
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->Put($data); // Delete($data)

扩展

文件上传

About

Curl Http Client Builder, Support GET, POST, PUT, DELETE Method

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages