当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpRequest::setRawPostData方法代码示例

本文整理汇总了PHP中HttpRequest::setRawPostData方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpRequest::setRawPostData方法的具体用法?PHP HttpRequest::setRawPostData怎么用?PHP HttpRequest::setRawPostData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest::setRawPostData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendRequest

 /**
  * Send the request
  *
  * This function sends the actual request to the
  * remote/local webserver using pecl http
  *
  * @link http://us2.php.net/manual/en/http.request.options.php
  * @todo catch exceptions from HttpRequest and rethrow
  * @todo handle Puts
  */
 public function sendRequest()
 {
     $options = array('connecttimeout' => $this->requestTimeout);
     // if we have any listeners register an onprogress callback
     if (count($this->_listeners) > 0) {
         $options['onprogress'] = array($this, '_onprogress');
     }
     $tmp = 'HTTP_METH_' . strtoupper($this->verb);
     if (defined($tmp)) {
         $method = constant($tmp);
     } else {
         $method = HTTP_METH_GET;
     }
     $this->request = $request = new \HttpRequest($this->uri->url, $method, $options);
     $request->setHeaders($this->headers);
     if ($this->body) {
         $request->setRawPostData($this->body);
     }
     $request->send();
     $response = $request->getResponseMessage();
     $body = $response->getBody();
     $details = $this->uri->toArray();
     $details['code'] = $request->getResponseCode();
     $details['httpVersion'] = $response->getHttpVersion();
     $headers = new Request\Headers($response->getHeaders());
     $cookies = $request->getResponseCookies();
     return new Request\Response($details, $body, $headers, $cookies);
 }
开发者ID:kingsj,项目名称:core,代码行数:38,代码来源:Http.php

示例2: __call

 /**
  * RPC method proxy
  *
  * @param string $method RPC method name
  * @param array $params RPC method arguments
  * @return mixed decoded RPC response
  * @throws Exception
  */
 public function __call($method, array $params)
 {
     if (strlen($this->__namespace)) {
         $method = $this->__namespace . '.' . $method;
     }
     $this->__request->setContentType("text/xml");
     $this->__request->setRawPostData(xmlrpc_encode_request($method, $params, array("encoding" => $this->__encoding) + (array) $this->__options));
     $response = $this->__request->send();
     if ($response->getResponseCode() != 200) {
         throw new Exception($response->getResponseStatus(), $response->getResponseCode());
     }
     $data = xmlrpc_decode($response->getBody(), $this->__encoding);
     if (xmlrpc_is_fault($data)) {
         throw new Exception((string) $data['faultString'], (int) $data['faultCode']);
     }
     return $data;
 }
开发者ID:garybulin,项目名称:php7,代码行数:25,代码来源:XmlRpcClient.php

示例3: execute

 public static function execute($parameters)
 {
     $h = new \HttpRequest($parameters['server']['scheme'] . '://' . $parameters['server']['host'] . $parameters['server']['path'] . (isset($parameters['server']['query']) ? '?' . $parameters['server']['query'] : ''), static::$_methods[$parameters['method']], array('redirect' => 5));
     if ($parameters['method'] == 'post') {
         $h->setRawPostData($parameters['parameters']);
     }
     $h->send();
     return $h->getResponseBody();
 }
开发者ID:kdexter,项目名称:oscommerce,代码行数:9,代码来源:HttpRequest.php

示例4: request

 protected function request($uri, $method, $data)
 {
     $httpRequest = new HttpRequest();
     $httpRequest->setOptions(array("useragent" => "Scalr (https://scalr.net)"));
     $httpRequest->setUrl("{$this->apiUrl}{$uri}");
     $httpRequest->setMethod($method);
     $httpRequest->resetCookies();
     $httpRequest->addHeaders(array('Cookie' => $this->sessionCookie, 'Content-Type' => 'application/nimbula-v1+json'));
     switch ($method) {
         case HTTP_METH_POST:
             $httpRequest->setRawPostData(json_encode($data));
             $httpRequest->addHeaders(array('Content-Type' => 'application/nimbula-v1+json'));
             break;
     }
     try {
         $httpRequest->send();
         $data = $httpRequest->getResponseData();
         $result = @json_decode($data['body']);
         if ($httpRequest->getResponseCode() > 204) {
             $message = $result->message;
             if ($message) {
                 if ($message instanceof stdClass) {
                     $r = (array) $message;
                     $msg = '';
                     foreach ($r as $k => $v) {
                         $msg .= "{$k}: {$v} ";
                     }
                     throw new Exception(trim($msg));
                 } else {
                     throw new Exception($message);
                 }
             }
             throw new Exception($data['body']);
         }
         $headers = $httpRequest->getResponseHeader('Set-Cookie');
         if ($headers) {
             if (!is_array($headers)) {
                 if (stristr($headers, "nimbula")) {
                     $this->sessionCookie = $headers;
                 }
             } else {
             }
         }
         $this->LastResponseHeaders = $data['headers'];
         return $result;
     } catch (Exception $e) {
         if ($e->innerException) {
             $message = $e->innerException->getMessage();
         } else {
             $message = $e->getMessage();
         }
         throw new Exception("Nimbula error: {$message}");
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:54,代码来源:Connection.php

示例5: 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

示例6: request

 private function request($method, Object $params = null)
 {
     $requestObj = new stdClass();
     $requestObj->id = microtime(true);
     $requestObj->method = $method;
     $requestObj->params = $params;
     $jsonRequest = json_encode($requestObj);
     $timestamp = date("D d M Y H:i:s T");
     $dt = new DateTime($timestamp, new DateTimeZone("CDT"));
     $timestamp = Scalr_Util_DateTime::convertDateTime($dt, new DateTimeZone("UTC"), new DateTimeZone("CDT"))->format("D d M Y H:i:s");
     $timestamp .= " UTC";
     $canonical_string = $jsonRequest . $timestamp;
     $signature = base64_encode(hash_hmac('SHA1', $canonical_string, $this->dbServer->GetProperty(SERVER_PROPERTIES::SZR_KEY), 1));
     $request = new HttpRequest("http://{$this->dbServer->remoteIp}:{$this->port}/", HTTP_METH_POST);
     $request->setOptions(array('timeout' => 5, 'connecttimeout' => 5));
     $request->setHeaders(array("Date" => $timestamp, "X-Signature" => $signature, "X-Server-Id" => $this->dbServer->serverId));
     $request->setRawPostData($jsonRequest);
     try {
         // Send request
         $request->send();
         if ($request->getResponseCode() == 200) {
             $response = $request->getResponseData();
             $jResponse = @json_decode($response['body']);
             if ($jResponse->error) {
                 throw new Exception("{$jResponse->error->message} ({$jResponse->error->code}): {$jResponse->error->data}");
             }
             return $jResponse;
         } else {
             throw new Exception(sprintf("Unable to perform request to update client: %s", $request->getResponseCode()));
         }
     } catch (HttpException $e) {
         if (isset($e->innerException)) {
             $msg = $e->innerException->getMessage();
         } else {
             $msg = $e->getMessage();
         }
         throw new Exception(sprintf("Unable to perform request to update client: %s", $msg));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:39,代码来源:UpdateClient.php

示例7: Request

 private function Request($method, $uri, $request_body, $query_args, $headers = array())
 {
     $HttpRequest = new HttpRequest();
     $HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
     $timestamp = $this->GetTimestamp();
     $signature = $this->GetRESTSignature($timestamp);
     $HttpRequest->setUrl("https://cloudfront.amazonaws.com/" . self::API_VERSION . $uri);
     $HttpRequest->setMethod($method);
     if ($query_args) {
         $HttpRequest->addQueryData($query_args);
     }
     if ($request_body) {
         if ($method == constant("HTTP_METH_POST")) {
             $HttpRequest->setRawPostData(trim($request_body));
         } else {
             $HttpRequest->setPutData(trim($request_body));
         }
         $headers["Content-type"] = "text/xml";
     }
     $headers["Date"] = $timestamp;
     $headers["Authorization"] = "AWS {$this->AWSAccessKeyId}:{$signature}";
     $HttpRequest->addHeaders($headers);
     try {
         $HttpRequest->send();
         //$info = $HttpRequest->getResponseInfo();
         $data = $HttpRequest->getResponseData();
         $this->LastResponseHeaders = $data['headers'];
         return $data['body'];
     } catch (Exception $e) {
         if ($e->innerException) {
             $message = $e->innerException->getMessage();
         } else {
             $message = $e->getMessage();
         }
         throw new Exception($message);
     }
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:37,代码来源:class.AmazonCloudFront.php

示例8: sendRequest

 protected function sendRequest($uri, $method, $data = null)
 {
     try {
         $request = new HttpRequest("https://{$this->active_domain}.chargify.com{$uri}");
         $request->setHeaders(array('Content-Type' => 'application/xml'));
         $request->setOptions(array('httpauth' => "{$this->active_api_key}:x", 'timeout' => 45, 'connecttimeout' => 45));
         $request->setMethod(constant("HTTP_METH_{$method}"));
         if ($data) {
             $request->setRawPostData($data);
         }
     } catch (Exception $e) {
         //TODO:
         throw $e;
     }
     $request->send();
     return $request;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:17,代码来源:class.ChargifyConnector.php

示例9: call

 /**
  * Make a request to Fluidinfo API
  *
  * @param $method
  * @param $path
  * @param $params
  * @param $payload
  * @return object
  */
 public function call($method, $path, $params = null, $payload = null, $contenttype = 'application/json', $inPool = false)
 {
     $url = $this->prefix . $path;
     if ($params) {
         $url .= '?' . $this->array2url($params);
     }
     $ch = new HttpRequest();
     $met = 0;
     if ($method == 'POST') {
         $met = HTTP_METH_POST;
     } else {
         if ($method == 'PUT') {
             $met = HTTP_METH_PUT;
         } else {
             if ($method == 'DELETE') {
                 $met = HTTP_METH_DELETE;
             } else {
                 if ($method == 'GET') {
                     $met = HTTP_METH_GET;
                 } else {
                     if ($method == 'HEAD') {
                         $met = HTTP_METH_HEAD;
                     } else {
                     }
                 }
             }
         }
     }
     $ch->setMethod($met);
     if ($this->credentials) {
         $ch->setOptions(array('url' => $url, 'timeout' => 65, 'low_speed_time' => 65, 'useragent' => 'fluid-phpv1.1', 'httpauth' => $this->credentials));
     } else {
         $ch->setOptions(array('url' => $url, 'timeout' => 65, 'low_speed_time' => 65, 'useragent' => 'fluid-phpv1.1'));
     }
     $headers = array();
     if ($method != 'GET') {
         if ($payload or $method == 'PUT') {
             $payload = json_encode($payload);
             //$ch->setPutData($payload);
             $headers[] = 'Content-Type: ' . $contenttype;
             $headers[] = 'Content-Length: ' . strlen($payload);
             if ($method == 'POST') {
                 $ch->setRawPostData($payload);
             } else {
                 $ch->setPutData($payload);
             }
             $ch->setContentType($contenttype);
         }
     }
     $ch->addHeaders($headers);
     $ch->addHeaders(array('Expect' => ''));
     if ($inPool == false) {
         $response = $ch->send();
         $infos = $response->getHeaders();
         $output = $response->getBody();
         if ($infos['Content-Type'] == 'application/json' or $infos['Content-Type'] == 'application/vnd.fluiddb.value+json') {
             $output = json_decode($output);
         }
         $return_arr = array($response->getResponseCode(), $output, implode("\n", $infos));
         print "<pre>";
         print "Returning for method " . $method . "<br />";
         print_r($return_arr);
         print "<br />";
         print "</pre>";
         return $return_arr;
     } else {
         $this->pool->attach($ch);
     }
 }
开发者ID:npetrovi,项目名称:fluidinfo.php,代码行数:78,代码来源:fluidinfo.php

示例10: SendMessage

 /**
  * Send message to instance
  * @param Scalr_Messaging_Msg $message
  * @return Scalr_Messaging_Msg
  */
 public function SendMessage(Scalr_Messaging_Msg $message, $isEventNotice = false, $delayed = false)
 {
     if ($this->farmId) {
         if ($this->GetFarmObject()->Status == FARM_STATUS::TERMINATED) {
             $this->Db->Execute("UPDATE messages SET status = ? WHERE messageid = ?", array(MESSAGE_STATUS::FAILED, $message->messageId));
             return;
         }
     }
     $logger = Logger::getLogger('DBServer');
     $serializer = Scalr_Messaging_XmlSerializer::getInstance();
     $cryptoTool = Scalr_Messaging_CryptoTool::getInstance();
     $rawMessage = $serializer->serialize($message);
     // Add message to database
     $this->Db->Execute("INSERT INTO messages SET\r\n\t\t\t\t`messageid`\t= ?,\r\n\t\t\t\t`server_id`\t= ?,\r\n\t\t\t\t`message`\t= ?,\r\n\t\t\t\t`type`\t\t= 'out',\r\n\t\t\t\t`message_name` = ?,\r\n\t\t\t\t`handle_attempts` = ?,\r\n\t\t\t\t`message_version` = ?,\r\n\t\t\t\t`dtlasthandleattempt` = NOW()\r\n\t\t\tON DUPLICATE KEY UPDATE handle_attempts = handle_attempts+1, dtlasthandleattempt = NOW()  \r\n\t\t\t", array($message->messageId, $this->serverId, $rawMessage, $message->getName(), $delayed ? '0' : '1', $this->IsSupported("0.5") ? 2 : 1));
     if ($this->platform == SERVER_PLATFORMS::RDS) {
         $logger->info("RDS platform doesn't support messaging. Skipping...");
         $this->Db->Execute("UPDATE messages SET status = ? WHERE messageid = ?", array(MESSAGE_STATUS::UNSUPPORTED, $message->messageId));
         return $message;
     }
     if ($delayed) {
         return $message;
     }
     if ($this->IsSupported("0.5") && !$isEventNotice) {
         if (!$this->remoteIp) {
             return;
         }
         // Put access data and reserialize message
         $pl = PlatformFactory::NewPlatform($this->platform);
         $pl->PutAccessData($this, $message);
         $rawMessage = $serializer->serialize($message);
         $cryptoKey = $this->GetKey(true);
         $encMessage = $cryptoTool->encrypt($rawMessage, $cryptoKey);
         list($signature, $timestamp) = $cryptoTool->sign($encMessage, $cryptoKey);
         try {
             $ctrlPort = $this->GetProperty(SERVER_PROPERTIES::SZR_CTRL_PORT);
             if (!$ctrlPort) {
                 $ctrlPort = 8013;
             }
             // Prepare request
             $request = new HttpRequest("http://{$this->remoteIp}:{$ctrlPort}/control", HTTP_METH_POST);
             $request->setOptions(array('timeout' => 4, 'connecttimeout' => 4));
             $request->setHeaders(array("Date" => $timestamp, "X-Signature" => $signature));
             $request->setRawPostData($encMessage);
             // Send request
             $request->send();
             // Process response
             if ($request->getResponseCode() == 201) {
                 $logger->info(sprintf("[FarmID: %s] Sending message '%s' via REST to server '%s' (server_id: %s) complete", $this->farmId, $message->getName(), $this->remoteIp, $this->serverId));
                 $this->Db->Execute("UPDATE messages SET status = ?, message = '' WHERE messageid = ?", array(MESSAGE_STATUS::HANDLED, $message->messageId));
             } else {
                 $logger->warn(sprintf("[FarmID: %s] Cannot deliver message '%s' (message_id: %s) via REST" . " to server '%s' (server_id: %s). Error: %s %s", $this->farmId, $message->getName(), $message->messageId, $this->remoteIp, $this->serverId, $request->getResponseCode(), $request->getResponseStatus()));
             }
         } catch (HttpException $e) {
             if (isset($e->innerException)) {
                 $msg = $e->innerException->getMessage();
             } else {
                 $msg = $e->getMessage();
             }
             if ($this->farmId) {
                 $logger->warn(new FarmLogMessage($this->farmId, sprintf("Cannot deliver message '%s' (message_id: %s) via REST" . " to server '%s' (server_id: %s). Error: %s %s", $message->getName(), $message->messageId, $this->remoteIp, $this->serverId, $request->getResponseCode(), $msg)));
             } else {
                 $logger->fatal(sprintf("Cannot deliver message '%s' (message_id: %s) via REST" . " to server '%s' (server_id: %s). Error: %s %s", $message->getName(), $message->messageId, $this->remoteIp, $this->serverId, $request->getResponseCode(), $msg));
             }
             return false;
         }
     } else {
         if ($this->remoteIp) {
             $community = $this->Db->GetOne("SELECT hash FROM farms WHERE id=?", array($this->farmId));
             $snmpClient = new Scalr_Net_Snmp_Client();
             $snmpClient->connect($this->remoteIp, 162, $community);
             $converter = Scalr_Messaging_SnmpConverter::getInstance();
             $trap = $converter->convert($message, $isEventNotice);
             $res = $snmpClient->sendTrap($trap);
             Logger::getLogger('DBServer')->info("[FarmID: {$this->farmId}] Sending message " . $message->getName() . " via SNMP ({$trap}) to '{$this->serverId}' ('{$this->remoteIp}') complete ({$res})");
         }
     }
     return $message;
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:83,代码来源:class.DBServer.php


注:本文中的HttpRequest::setRawPostData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。