panwenbin / curl

curl 简单封装

0.2.1 2020-02-13 16:40 UTC

This package is not auto-updated.

Last update: 2024-09-20 07:20:04 UTC


README

curl 简单封装,目前主要为了方便地实现 GET/POST/PATCH/HEAD/OPTIONS/DELETE,替代 file_get_contents

简单使用示例

use panwenbin\helper\Curl;

$res = Curl::to('https://github.com/panwenbin')->withHeader('User-Agent', 'PHP CURL')->get();
$res = Curl::to('http://www.example.com/')->withData(['username' => 'panwenbin', 'password' => 'password'])->post();
$res = Curl::to('http://www.example.com/source/1')->withData(['minPriceYuan' => 123])->patch();
$res = Curl::to('http://www.example.com/')->withData(['product_id' => '123'])->get();
$res = Curl::to('http://www.example.com/profile')->withCookieFile('cookiejar.txt')->get();
$imageFile = new \CURLFile($filename);
$res = Curl::to($uploadUrl)->withData(['media' => $imageFile])->withOption(CURLOPT_TIMEOUT, 180)->post();
if ($res->code == 200) {
    $html = $res->body;
}