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


PHP HttpRequest::getResponseHeader方法代码示例

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


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

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

示例2: testStoreAsset

 public function testStoreAsset()
 {
     $headers = array('X-Asset-Creator-Id' => (string) UUID::Random(), 'X-Asset-Id' => UUID::Zero);
     $r = new HttpRequest($this->server_url, HttpRequest::METH_POST);
     $r->addHeaders($headers);
     $r->AddPostFile(UUID::Random(), "eyewhite.tga", "image/tga");
     $r->send();
     $this->AssetSHA = sha1(file_get_contents('eyewhite.tga'));
     $this->assertEquals(201, $r->getResponseCode());
     if (file_exists('test.assetid')) {
         unlink('test.assetid');
     }
     file_put_contents('test.assetid', (string) UUID::Parse($r->getResponseHeader("X-Asset-Id")));
 }
开发者ID:QuillLittlefeather,项目名称:mgm-simiangrid,代码行数:14,代码来源:AssetServiceTests.php

示例3: doDelete

 protected function doDelete($action, array $data)
 {
     $module = empty($action) ? substr($this->module, 0, -1) : $this->module;
     if (strrpos($action, '.json') === false) {
         $action .= '.json';
     }
     array_walk_recursive($data, 'Lupin_Model_API::encode');
     $url = $this->hostname . $module . $action;
     $request = new HttpRequest($url, HTTP_METH_DELETE);
     $request->setQueryData($data);
     try {
         $request->send();
     } catch (Exception $e) {
         return false;
     }
     $this->responseCode = $request->getResponseCode();
     if ($request->getResponseCode() !== 200) {
         return false;
     }
     return $request->getResponseHeader();
 }
开发者ID:jeremykendall,项目名称:spaz-api,代码行数:21,代码来源:API.php

示例4: catch

<soap:Body>
<GetWeather xmlns="http://www.webserviceX.NET">
<CityName>singapore</CityName>
<CountryName>singapore</CountryName>
</GetWeather>
</soap:Body>
</soap:Envelope>';
$r->setBody($xmlSoapMessage);
try {
    $r->send();
    echo '<h2>Request Header</h2>';
    echo '<pre>';
    print_r($r->getRawRequestMessage());
    echo '</pre>';
    $responseCode = $r->getResponseCode();
    $responseHeader = $r->getResponseHeader();
    $responseBody = $r->getResponseBody();
    echo '--------------------------------------------------------------------------------------------<br/>';
    echo '<h2>Rseponse Code</h2>';
    echo "resonse code " . $responseCode . "<br/>";
    // echo "resonse header" . $responseHeader["location"] . "<br/>";
    echo '<h2>Rseponse Header</h2>';
    echo '<pre>';
    print_r($responseHeader);
    echo '</pre>';
    echo '<h2>Rseponse Body</h2>';
    echo '<pre>';
    print_r($responseBody);
    echo '</pre>';
} catch (HttpException $ex) {
    echo $ex;
开发者ID:jipengxiang,项目名称:phpWebService,代码行数:31,代码来源:temperatureConversionSOAP.php

示例5: isExpired

 /**
  * @static
  * @param HttpRequest $resp
  * @return bool True if the HTTP response is considered to be expired.
  * False if it is considered to be fresh.
  */
 public static function isExpired(HttpRequest $resp)
 {
     // HTTP/1.1 clients and caches MUST treat other invalid date formats,
     // especially including the value “0”, as in the past.
     $parsedExpires = false;
     $responseHeaders = $resp->getResponseHeaders();
     if (isset($responseHeaders['expires'])) {
         $rawExpires = $responseHeaders['expires'];
         // Check for a malformed expires header first.
         if (empty($rawExpires) || is_numeric($rawExpires) && $rawExpires <= 0) {
             return true;
         }
         // See if we can parse the expires header.
         $parsedExpires = strtotime($rawExpires);
         if (false == $parsedExpires || $parsedExpires <= 0) {
             return true;
         }
     }
     // Calculate the freshness of an http response.
     $freshnessLifetime = false;
     $cacheControl = $resp->getParsedCacheControl();
     if (isset($cacheControl['max-age'])) {
         $freshnessLifetime = $cacheControl['max-age'];
     }
     $rawDate = $resp->getResponseHeader('date');
     $parsedDate = strtotime($rawDate);
     if (empty($rawDate) || false == $parsedDate) {
         $parsedDate = time();
     }
     if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
         $freshnessLifetime = $parsedExpires - $parsedDate;
     }
     if (false == $freshnessLifetime) {
         return true;
     }
     // Calculate the age of an http response.
     $age = max(0, time() - $parsedDate);
     if (isset($responseHeaders['age'])) {
         $age = max($age, strtotime($responseHeaders['age']));
     }
     return $freshnessLifetime <= $age;
 }
开发者ID:orvice,项目名称:google-api,代码行数:48,代码来源:CacheParser.php

示例6: _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:sysdevbol,项目名称:entidad,代码行数:34,代码来源:external.php


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