urmaul/httpclient
该软件包已被废弃且不再维护。没有建议的替代软件包。
这是一个curl的PHP封装。
1.1.1
2016-07-07 15:32 UTC
Requires
- php: >=5.3
- lib-curl: *
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2020-01-24 15:15:45 UTC
README
这是一个curl的PHP封装。
主要想法只是用一行代码发送HTTP请求。并且默认支持Cookie。
对于更复杂的需求,你可能需要使用Guzzle。
如何使用
就像这样。
HttpClient::from(['useRandomCookieFile' => true])->get('http://httpbin.org/get'); HttpClient::from()->post('http://httpbin.org/post', ['foo' => 'bar']); HttpClient::from()->download('http://httpbin.org/image/jpeg', 'my-new-image-file.jpeg');
方法
- head($url, $params = array()) - 发送HTTP请求获取响应头。
- get($url, $params = array()) - 发送HTTP GET请求。
- post($url, $post = array(), $params = array()) - 发送HTTP POST请求。
- download($url, $dest, $post = array(), $params = array()) - 下载文件。
- request($params) - 发送HTTP请求。
- getInfo($opt = null) - 返回关于最后一次传输的信息。 详细信息
可能的 $params 值
- url - (string) 请求URL。
- post - (string|array) 请求POST数据。
- ref - (string) "Referer" 请求头内容。
- header - (boolean, 默认 = false) 是否将响应头包含在响应中。
- nobody - (boolean, 默认 = false) 是否不包含响应体在响应中。
- timeout - (integer, 默认 = 15) 请求超时。
- tofile - (string, 默认 = null) 输出文件名。如果定义了,响应将被保存到该文件。
- attempts_max - (integer, 默认 = 1) 执行HTTP请求的最大尝试次数。
- attempts_delay - (integer, 默认 = 10) 尝试之间的延迟,以秒为单位
只读属性
- $lastError - (string) 最后一次请求错误。
- $info - (array) 关于最后一次传输的信息。
- $httpCode - (integer) 最后接收到的HTTP代码。
- $effectiveUrl - (string) 最后有效的URL。
- $cookies - (array) Cookie数组。 注意:调用此属性后,将无法获取其他属性。