一个轻量级的php http客户端:dHttp

jopen 10年前

dHttp是一个基于CUrl的轻量级php http客户端。易于使用。

GET request:
include_once('dHttp/Client.php');  include_once('dHttp/Response.php');    $http = new dHttp\Client('http://website.com');    $resp = $http->get();  // Get response code  var_dump($resp->getCode());  // Get response body  var_dump($resp->getBody());  // Get request errors  var_dump($resp->getErrors());  // Return response headers  var_dump($resp->getHeaders());  // Return a specific (text/html; charset=utf-8)  var_dump($resp->getHeader('Content-Type'));

POST request:
include_once('dHttp/Client.php');  include_once('dHttp/Response.php');    $http = new dHttp\Client('http://website.com');    $http->addOptions(array(CURLOPT_RETURNTRANSFER => false))      ->setCookie('/tmp/cookie.txt')      ->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31')      ->post(array(          'field1' => 'value1',          'field2' => 'value2',  ));

Multithreaded query:
include_once('dHttp/Client.php');  include_once('dHttp/Response.php');    $multi = new dHttp\Client();  $response_array = $multi->multi(array(      new dHttp\Client('http://website1.com'),        new dHttp\Client('http://website2.com', array(          CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1',          CURLOPT_TIMEOUT => 5,      ))  ));    foreach($response_array as $item) {      var_dump($item->getCode());  }

</div>

项目主页:http://www.open-open.com/lib/view/home/1423555879404