spruce-bruce / curl
v0.1.0
2013-07-11 19:47 UTC
This package is not auto-updated.
Last update: 2024-09-23 12:51:44 UTC
README
这是一个curl的包装类,是我开发的一个curl简写。市面上有其他curl包装器,但我从来都不是它们的粉丝。
在这个类中,我实现了HTTP请求的静态方法:get()、post()、delete()和put()。
安装
您可以下载此存储库的zip文件(或克隆它)并包含Curl.php文件。如果您喜欢composer,我已经将此存储库添加到packagist,您可以通过将“spruce-bruce/composer” : “0.1.*”添加到您的需求中来进行安装。
用法
以下是一些虚构的例子,展示了Curl.php的使用。
POST
示例POST
//set the url $url = "http://somefictionaldomain.com/api"; //set the POST vars $data = array( 'query' => 'active', 'page' => 3, 'count' => 10 ); //get the post response $response = Curl::post($url, $data);
GET
带有额外curl选项的示例GET
//set the url $url = "http://somefictionaldomain.com/api"; //set the GET vars $data = array( 'query' => 'active', 'page' => 3, 'count' => 10 ); //set addtional curl options $options = array( CURLOPT_FAILONERROR => true ); //get the GET response $response = Curl::get($url, $data, $options);
默认curl选项
每种类型的HTTP请求都会有一些默认的curl选项被设置。默认值目前无法更改。默认值是根据我过去使用curl的经验确定的,即,它们是我通常会为特定HTTP请求类型设置的选项。
POST
- CURLOPT_RETURNTRANSFER
- CURLOPT_POST
- CURLOPT_POSTFIELDS (仅当$data参数被设置时)
GET
- CURLOPT_RETURNTRANSFER
DELETE
未实现
PUT
未实现
待办事项
- 实现delete()和put()方法
- 清理HTTP代码解析并使其更健壮(即,将响应中的任何消息添加到异常中)
- 保存并使响应头可访问
- 保存并使curl资源可访问
- 记录异常