當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpRequest::addPutData方法代碼示例

本文整理匯總了PHP中HttpRequest::addPutData方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpRequest::addPutData方法的具體用法?PHP HttpRequest::addPutData怎麽用?PHP HttpRequest::addPutData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest::addPutData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: request

 function request($url, $options = array())
 {
     $url = "http://" . $this->host . ":" . $this->port . $url;
     $method = HTTP_METH_GET;
     $headers = array("Host" => $this->host, "Referer" => "http://localhost/", "Content-Type" => "application/json");
     $params = '';
     foreach ($options as $name => $option) {
         switch ($name) {
             case "method":
                 $method = $option;
                 break;
             case "headers":
                 $headers = array_merge($option, $headers);
                 break;
             case "params":
                 $params = http_build_query($option);
                 break;
             case "postdata":
                 $post_data = $option;
                 break;
             default:
                 trigger_error("Unknown http option: {$name}", E_USER_WARNING);
         }
     }
     if (!empty($params)) {
         $url = $url . "?" . $params;
     }
     $request = new HttpRequest($url, $method);
     $request->setHeaders($headers);
     if (isset($post_data)) {
         if ($method == HTTP_METH_PUT) {
             $request->addPutData($post_data);
         } else {
             if ($method == HTTP_METH_POST) {
                 $request->setRawPostData($post_data);
             }
         }
     }
     $json = $request->send()->getBody();
     $data = json_decode($json, true);
     if (isset($data['rows'])) {
         $data = new CouchResult($data);
     }
     return $data;
 }
開發者ID:regality,項目名稱:zombie-core,代碼行數:45,代碼來源:CouchDB.php

示例2: sendRequest

 protected function sendRequest($uri, $method, $data = null)
 {
     try {
         $request = new HttpRequest("https://{$this->domain}.chargify.com{$uri}");
         $request->setHeaders(array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode("{$this->apiKey}:x")));
         $request->setOptions(array('httpauth' => "{$this->apiKey}:x", 'timeout' => 45, 'connecttimeout' => 45, 'ssl' => array('version' => 1)));
         $request->setMethod(constant("HTTP_METH_{$method}"));
         if ($method == 'POST' && $data) {
             $request->setBody($data);
         }
         if ($method == 'PUT') {
             $request->addPutData($data);
         }
     } catch (Exception $e) {
         //TODO:
         throw $e;
     }
     $request->send();
     if ($request->getResponseCode() == 500) {
         throw new Exception("Unable to proceed your request at the moment. Please try again later.");
     }
     if ($request->getResponseCode() == 404) {
         throw new Exception("Unable to proceed your request. Please contact billing@scalr.net to get help.");
     }
     return $request;
 }
開發者ID:sacredwebsite,項目名稱:scalr,代碼行數:26,代碼來源:class.Chargify.php


注:本文中的HttpRequest::addPutData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。