jojo's blog--快樂憂傷都與你同在
          為夢想而來,為自由而生。 性情若水,風起水興,風息水止,故時而激蕩,時又清平……
          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)  編輯  收藏

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


          網站導航:
           

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

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章分類

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 连山| 栖霞市| 孟连| 乌兰浩特市| 汉源县| 鹤岗市| 玉溪市| 台南县| 绍兴县| 灌阳县| 共和县| 彰化县| 逊克县| 五寨县| 怀来县| 南涧| 贡觉县| 泽库县| 炉霍县| 莱芜市| 隆尧县| 曲松县| 泰顺县| 鄂伦春自治旗| 佛山市| 集安市| 秦安县| 云梦县| 交口县| 渭南市| 辉南县| 阳江市| 酉阳| 莱州市| 台北市| 沁水县| 尉氏县| 永兴县| 定边县| 铜川市| 新平|