Home > Backend Development > PHP Tutorial > PHP易用的http客户端:curlpp

PHP易用的http客户端:curlpp

WBOY
Release: 2016-06-23 13:42:46
Original
1282 people have browsed it

curlpp是一个方便在php中发起http请求的C++扩展。基于libcurl开发。有别于已有的curl扩展。curlpp提供的接口更加简明,轻松发起GET/POST请求.

curlpp的主要特点是告别麻烦的设置过程,直面业务本身,在保证性能的前提下,加速开发和运行效率。


class curlpp {    public function set_proxy($host, $port);    public function set_proxy_credentials($username, $password);    public function set_auto_redirect($tf);    public function set_timeout($time);        public function set_head($head);        public function set_cookie($cookie);    public function get($uri, $data);    public function post($uri, $data);    public function head();    public function body();    public function status();    public function cookie();    public function size();}
Copy after login



curlpp统一的get/post请求是查询域的发送,统一使用参数数组参数$data发送请求数据集。无数据时用空数组即可。head和cookie也可以通过数组轻松设置。

demo:

$uri='http://www.baidu.com';$client = new curlpp();$client->set_head(array('User-Agent' => 'curlpp'));$client->set_cookie(array('key'=>vlaue));$client->set_auto_redirect(true);$client->set_timeout(3000);$data = array();$response = array();if($client->get($uri,$data)){    $response['head'] = $client->head();    $response['cookie'] = $client->cookie();    $response['status'] = $client->status();    $response['content-size'] = $client->size();    $response['content'] = $client->body();}else{    exit('error');}var_dump($response);
Copy after login




下载地址:http://www.wqbuyer.com/demo/


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template