lukaszjarosinski / restclient
简单快捷的 REST 客户端
dev-master
2022-01-20 11:42 UTC
Requires
- php: >=7.0.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- php: >=7.0.0
- phpunit/phpunit: >=4.5
This package is not auto-updated.
Last update: 2024-09-27 23:52:24 UTC
README
https://github.com/lukaszjarosinski/restclient (c) 2022 lukaszjarosinski@gmail.com
安装
$ php composer.phar require lukaszjarosinski/restclient
基本用法
$client = new Client(); $headers = array("Content-Type" => "application/x-www-form-urlencoded"); //example headers, unnecessary $parameters = array('name'=>'Name','gender'=>'male','email'=>'email@email.com','status'=>'active'); //example parameters, unnecessary $client->get('http://www.boredapi.com/api/activity'); //url echo "<pre>"; var_dump($client->returnResponse()); echo "</pre>";
可配置选项
headers
- 一个包含要包含在每个请求中的 HTTP 头和值的关联数组。
parameters
- 一个包含要包含在每个请求中的 URL 或体参数的关联数组。
user_agent
- 用于请求的用户代理字符串。
username
- 用于 HTTP 基本认证的用户名。需要 password
。
password
- 用于 HTTP 基本认证的密码。需要 username
。
支持的方法
该工具支持 GET、POST、PATCH、DELETE 方法。示例
$client->get('http://www.boredapi.com/api/activity'); $client->post('https://gorest.co.in/public/v1/users',array('name'=>'Name','gender'=>'male','email'=>'email@email.com','status'=>'active'),array('Authorization'=>'Bearer '.$token));