当前位置:Gxlcms > PHP教程 > PHP易用的http客户端:curlpp

PHP易用的http客户端:curlpp

时间:2021-07-01 10:21:17 帮助过:30人阅读

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();}



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);




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

人气教程排行