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


PHP Google_HttpRequest::getResponseHttpCode方法代碼示例

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


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

示例1: decodeHttpResponse

 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_ServiceException
  * @param Google_HttpRequest $response The http response to be decoded.
  * @return mixed|null
  */
 public static function decodeHttpResponse($response)
 {
     $code = $response->getResponseHttpCode();
     $body = $response->getResponseBody();
     $decoded = null;
     if (intVal($code) >= 300) {
         $decoded = json_decode($body, true);
         $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
         if ($decoded != null && isset($decoded['error']['message']) && isset($decoded['error']['code'])) {
             // if we're getting a json encoded error definition, use that instead of the raw response
             // body for improved readability
             $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
         } else {
             $err .= ": ({$code}) {$body}";
         }
         throw new Google_ServiceException($err, $code, null, $decoded['error']['errors']);
     }
     // Only attempt to decode the response, if the response code wasn't (204) 'no content'
     if ($code != '204') {
         $decoded = json_decode($body, true);
         if ($decoded === null || $decoded === "") {
             throw new Google_ServiceException("Invalid json in service response: {$body}");
         }
     }
     return $decoded;
 }
開發者ID:jenia-buianov,項目名稱:all_my_sites,代碼行數:33,代碼來源:Google_REST.php


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