首页 > 技术文章 > 模拟请求之 HTTP_Request2

uniqid 2014-04-12 12:04 原文

简单安装:
pear install HTTP_Request2

使用例子:

 1 <?php
 2 require_once 'HTTP/Request2.php';
 3 $request = new HTTP_Request2('http://localhost/', HTTP_Request2::METHOD_GET);
 4 try {
 5     $response = $request->send();
 6     if (200 == $response->getStatus()) {
 7         echo $response->getBody();
 8     } else {
 9         echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
10              $response->getReasonPhrase();
11     }
12 } catch (HTTP_Request2_Exception $e) {
13     echo 'Error: ' . $e->getMessage();
14 }
15 ?>

 

详情:http://pear.php.net/manual/en/package.http.http-request2.intro.php

推荐阅读