jojo's blog--快樂憂傷都與你同在
          為夢想而來,為自由而生。 性情若水,風(fēng)起水興,風(fēng)息水止,故時而激蕩,時又清平……
          posts - 11,  comments - 30,  trackbacks - 0
          http://www.sematopia.com/?p=153

          The class below is RESTclient. Note, I put this together to prove a point, it still needs some work if you plan on using it.

          Code:
          <?php

          require_once "HTTP/Request.php";

          class RESTClient {

          private $root_url = "";
          private $curr_url = "";
          private $user_name = "";
          private $password = "";
          private $response = "";
          private $responseBody = "";
          private $req = null;

          public function __construct($root_url = "", $user_name = "", $password = "") {
          $this->root_url = $this->curr_url = $root_url;
          $this->user_name = $user_name;
          $this->password = $password;
          if ($root_url != "") {
          $this->createRequest("GET");
          $this->sendRequest();
          }
          return true;
          }

          public function createRequest($url, $method, $arr = null) {
          $this->curr_url = $url;
          $this->req =& new HTTP_Request($url);
          if ($this->user_name != "" && $this->password != "") {
          $this->req->setBasicAuth($this->user_name, $this->password);
          }

          switch($method) {
          case "GET":
          $this->req->setMethod(HTTP_REQUEST_METHOD_GET);
          break;
          case "POST":
          $this->req->setMethod(HTTP_REQUEST_METHOD_POST);
          $this->addPostData($arr);
          break;
          case "PUT":
          $this->req->setMethod(HTTP_REQUEST_METHOD_PUT);
          // to-do
          break;
          case "DELETE":
          $this->req->setMethod(HTTP_REQUEST_METHOD_DELETE);
          // to-do
          break;
          }
          }

          private function addPostData($arr) {
          if ($arr != null) {
          foreach ($arr as $key => $value) {
          $this->req->addPostData($key, $value);
          }
          }
          }

          public function sendRequest() {
          $this->response = $this->req->sendRequest();

          if (PEAR::isError($this->response)) {
          echo $this->response->getMessage();
          die();
          } else {
          $this->responseBody = $this->req->getResponseBody();
          }
          }

          public function getResponse() {
          return $this->responseBody;
          }

          }
          ?>

          posted on 2008-10-07 17:10 Blog of JoJo 閱讀(157) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章分類

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 隆子县| 南郑县| 梅河口市| 观塘区| 木里| 乐都县| 宁晋县| 越西县| 成武县| 天津市| 星子县| 安宁市| 乌拉特后旗| 合作市| 洮南市| 闽清县| 岑溪市| 乌兰县| 沿河| 阿拉善盟| 青州市| 靖远县| 普兰店市| 建德市| 荣成市| 思南县| 仁怀市| 永顺县| 寿宁县| 辽宁省| 时尚| 老河口市| 化州市| 溧阳市| 英吉沙县| 嘉禾县| 桃园县| 揭东县| 高碑店市| 江门市| 盱眙县|