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


PHP HTTPRequest::setBody方法代碼示例

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


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

示例1: _send_message

 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
     // Create an http request object
     $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
     if ($this->_options) {
         // Set custom options
         $http_request->setOptions($this->_options);
     }
     // Set headers
     $http_request->setHeaders($request->headers()->getArrayCopy());
     // Set cookies
     $http_request->setCookies($request->cookie());
     // Set query data (?foo=bar&bar=foo)
     $http_request->setQueryData($request->query());
     // Set the body
     if ($request->method() == HTTP_Request::PUT) {
         $http_request->addPutData($request->body());
     } else {
         $http_request->setBody($request->body());
     }
     try {
         $http_request->send();
     } catch (HTTPRequestException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPMalformedHeaderException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPEncodingException $e) {
         throw new Request_Exception($e->getMessage());
     }
     // Build the response
     $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
     return $response;
 }
開發者ID:artbypravesh,項目名稱:morningpages,代碼行數:42,代碼來源:HTTP.php

示例2: _http_execute

 /**
  * Execute the request using the PECL HTTP extension. (recommended)
  *
  * @param   Request   $request Request to execute
  * @return  Response
  */
 protected function _http_execute(Request $request)
 {
     $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
     // Create an http request object
     $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
     // Set custom options
     $http_request->setOptions($this->_options);
     // Set headers
     $http_request->setHeaders($request->headers()->getArrayCopy());
     // Set cookies
     $http_request->setCookies($request->cookie());
     // Set body
     $http_request->setBody($request->body());
     try {
         $http_request->send();
     } catch (HTTPRequestException $e) {
         throw new Kohana_Request_Exception($e->getMessage());
     } catch (HTTPMalformedHeaderException $e) {
         throw new Kohana_Request_Exception($e->getMessage());
     } catch (HTTPEncodingException $e) {
         throw new Kohana_Request_Exception($e->getMessage());
     }
     // Create the response
     $response = $request->create_response();
     // Build the response
     $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
     return $response;
 }
開發者ID:ricasiano,項目名稱:sapakan,代碼行數:34,代碼來源:external.php

示例3: urlencode

// over and over to demonstrate the performance benefit of keeping your
// TCP connection alive between requests. By minimizing the HTTP overhead
// in this manner, you nearly double your speed.
// Your authentication ID/token (obtained in your SmartyStreets account)
$authId = urlencode("raw id here");
$authToken = urlencode("raw token here");
// The REST endpoint
$url = "https://api.smartystreets.com/street-address/?auth-id={$authId}&auth-token={$authToken}";
// Your input to the API...
$addresses = array(array("street" => "1 infinite loop", "city" => "cupertino", "state" => "ca", "zipcode" => "95014", "candidates" => 10), array("street" => "1600 pennsylvania Ave.", "zipcode" => "20500", "candidates" => 3));
// LiveAddress API expects JSON input by default, but you could send XML
// if you set the Content-Type header to "text/xml".
$post = json_encode($addresses);
// Prepare the POST request, and set the body of it.
$request = new HTTPRequest($url, HTTP_METH_POST);
$request->setBody($post);
// Simple statistic variables
$max = 0;
$min = 99999999;
$sum = 0;
$requests = 100;
echo "<pre>";
// Do the requests, and time it
for ($i = 0; $i < $requests; $i++) {
    $start = microtime(true);
    $request->send();
    // In a real case, you'd call setBody() before this, to do the next 100 addresses
    $end = microtime(true);
    $ms = ($end - $start) * 1000;
    // For the record, you can get the response with:
    // $response = $request->getResponseBody();
開發者ID:biba1403,項目名稱:LiveAddressSamples,代碼行數:31,代碼來源:post_optimized_pecl.php

示例4: send

 /**
  * 發送notification或message。請閱讀友盟文檔。
  */
 public function send($data)
 {
     $token = $this->grantToken();
     $newData = $data;
     foreach ($token as $k => $v) {
         $newData[$k] = $v;
     }
     //必填 消息發送類型,其值為unicast,listcast,broadcast,groupcast或customizedcast
     if (!isset($data['type'])) {
         throw new Exception('need param: type');
     }
     // 可選 當type=customizedcast時,開發者填寫自己的alias,友盟根據alias進行反查找,得到對應的device_token。多個alias時用英文逗號分,不能超過50個。
     if (isset($data['alias']) && !empty($data['alias'])) {
         if (is_array($data['alias'])) {
             $newData['alias'] = implode(',', $data['alias']);
         } else {
             $newData['alias'] = $data['alias'];
         }
     }
     // 必填 消息類型,值為notification或者message
     if (!isset($data['payload']['display_type'])) {
         $newData['payload']['display_type'] = 'notification';
     }
     // 必填 通知欄提示文字。但實際沒有用,todo確認
     if (!isset($data['payload']['body']['ticker'])) {
         $newData['payload']['body']['ticker'] = $data['payload']['body']['title'];
     }
     //可選 消息描述。用於友盟推送web管理後台,便於查看。
     if (!isset($data['description'])) {
         $newData['description'] = $data['payload']['body']['title'];
     }
     $defaultTrueParams = array('play_vibrate', 'play_lights', 'play_sound');
     foreach ($defaultTrueParams as $one) {
         if (isset($data['payload']['body'][$one]) && ($data['payload']['body'][$one] == false || $data['payload']['body'][$one] == 'false')) {
             $newData['payload']['body'][$one] = 'false';
         }
     }
     $http = new \HTTPRequest($this->conf['api_uri_prefix'] . 'api/send', HTTP_METH_POST);
     $http->setBody(json_encode($newData));
     $http->send();
     $body = $http->getResponseBody();
     if ($http->getResponseCode() != 200) {
         throw new Exception($body);
     }
     $tmp = json_decode($body, true);
     if (!isset($tmp['ret']) || $tmp['ret'] != 'SUCCESS') {
         throw new Exception($body);
     }
     return true;
 }
開發者ID:sinkcup,項目名稱:umeng-message-sdk-php,代碼行數:53,代碼來源:Client.php


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