一个轻量级的php http客户端:dHttp
dHttp是一个基于CUrl的轻量级php http客户端。易于使用。 GET request:
POST request:
Multithreaded query:
</div>
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()); }
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!