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


PHP Google_Http_Request類代碼示例

本文整理匯總了PHP中Google_Http_Request的典型用法代碼示例。如果您正苦於以下問題:PHP Google_Http_Request類的具體用法?PHP Google_Http_Request怎麽用?PHP Google_Http_Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: sign

 public function sign(Google_Http_Request $request)
 {
     $this->key = $this->client->getClassConfig($this, 'key');
     if ($this->key) {
         $request->setRequestHeaders(array('Authorization' => $this->key));
     }
     return $request;
 }
開發者ID:TECHNOAPES,項目名稱:silverback-php-client,代碼行數:8,代碼來源:HeaderToken.php

示例2: sign

 public function sign(Google_Http_Request $request)
 {
     $key = $this->client->getClassConfig($this, 'developer_key');
     if ($key) {
         $request->setQueryParam('key', $key);
     }
     return $request;
 }
開發者ID:Kevin-ZK,項目名稱:vaneDisk,代碼行數:8,代碼來源:Simple.php

示例3: sign

 public function sign(Google_Http_Request $request)
 {
     $key = $this->client->getClassConfig($this, 'developer_key');
     if ($key) {
         $this->client->getLogger()->debug('Simple API Access developer key authentication');
         $request->setQueryParam('key', $key);
     }
     return $request;
 }
開發者ID:kkhalasi,項目名稱:cloudrouter.github.io,代碼行數:9,代碼來源:Simple.php

示例4: testDecodeEmptyResponse

 public function testDecodeEmptyResponse()
 {
     $url = 'http://localhost';
     $response = new Google_Http_Request($url, 'GET', array());
     $response->setResponseBody('{}');
     $response->setResponseHttpCode(200);
     $decoded = $this->rest->decodeHttpResponse($response);
     $this->assertEquals(array(), $decoded);
 }
開發者ID:rickb838,項目名稱:scalr,代碼行數:9,代碼來源:RestTest.php

示例5: sign

 public function sign(Google_Http_Request $request)
 {
     if (!$this->token) {
         // No token, so nothing to do.
         return $request;
     }
     // Add the OAuth2 header to the request
     $request->setRequestHeaders(array('Authorization' => 'Bearer ' . $this->token['access_token']));
     return $request;
 }
開發者ID:ankitbhattgit,項目名稱:wp,代碼行數:10,代碼來源:AppIdentity.php

示例6: sign

 public function sign(Google_Http_Request $request)
 {
     if (!$this->token) {
         // No token, so nothing to do.
         return $request;
     }
     $this->client->getLogger()->debug('App Identity authentication');
     // Add the OAuth2 header to the request
     $request->setRequestHeaders(array('Authorization' => 'Bearer ' . $this->token['access_token']));
     return $request;
 }
開發者ID:educakanchay,項目名稱:campus,代碼行數:11,代碼來源:AppIdentity.php

示例7: executeRequest

 /**
  * Execute an HTTP Request
  *
  * @param Google_Http_Request $request the http request to be executed
  * @return array containing response headers, body, and http code
  * @throws Google_IO_Exception on curl or IO error
  */
 public function executeRequest(Google_Http_Request $request)
 {
     $curl = curl_init();
     if ($request->getPostBody()) {
         curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody());
     }
     $requestHeaders = $request->getRequestHeaders();
     if ($requestHeaders && is_array($requestHeaders)) {
         $curlHeaders = array();
         foreach ($requestHeaders as $k => $v) {
             $curlHeaders[] = "{$k}: {$v}";
         }
         if (isset($this->options[CURLOPT_HTTPHEADER])) {
             if (is_array($this->options[CURLOPT_HTTPHEADER])) {
                 foreach ($this->options[CURLOPT_HTTPHEADER] as $optionHeader) {
                     $curlHeaders[] = $optionHeader;
                 }
             }
             unset($this->options[CURLOPT_HTTPHEADER]);
         }
         curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
     }
     curl_setopt($curl, CURLOPT_URL, $request->getUrl());
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
     curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent());
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
     // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
     curl_setopt($curl, CURLOPT_SSLVERSION, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HEADER, true);
     if ($request->canGzip()) {
         curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
     }
     $options = $this->client->getClassConfig('Google_IO_Curl', 'options');
     if (is_array($options)) {
         $this->setOptions($options);
     }
     foreach ($this->options as $key => $var) {
         curl_setopt($curl, $key, $var);
     }
     if (!isset($this->options[CURLOPT_CAINFO])) {
         curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem');
     }
     $this->client->getLogger()->debug('cURL request', array('url' => $request->getUrl(), 'method' => $request->getRequestMethod(), 'headers' => $requestHeaders, 'body' => $request->getPostBody()));
     $response = curl_exec($curl);
     if ($response === false) {
         $error = curl_error($curl);
         $code = curl_errno($curl);
         $map = $this->client->getClassConfig('Google_IO_Exception', 'retry_map');
         $this->client->getLogger()->error('cURL ' . $error);
         throw new Google_IO_Exception($error, $code, null, $map);
     }
     $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
     list($responseHeaders, $responseBody) = $this->parseHttpResponse($response, $headerSize);
     $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $this->client->getLogger()->debug('cURL response', array('code' => $responseCode, 'headers' => $responseHeaders, 'body' => $responseBody));
     return array($responseBody, $responseHeaders, $responseCode);
 }
開發者ID:andywooyay,項目名稱:google-api-php-client,代碼行數:66,代碼來源:Curl.php

示例8: parseResponse

 public function parseResponse(Google_Http_Request $response)
 {
     $contentType = $response->getResponseHeader('content-type');
     $contentType = explode(';', $contentType);
     $boundary = false;
     foreach ($contentType as $part) {
         $part = explode('=', $part, 2);
         if (isset($part[0]) && 'boundary' == trim($part[0])) {
             $boundary = $part[1];
         }
     }
     $body = $response->getResponseBody();
     if ($body) {
         $body = str_replace("--{$boundary}--", "--{$boundary}", $body);
         $parts = explode("--{$boundary}", $body);
         $responses = array();
         foreach ($parts as $part) {
             $part = trim($part);
             if (!empty($part)) {
                 list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
                 $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders);
                 $status = substr($part, 0, strpos($part, "\n"));
                 $status = explode(" ", $status);
                 $status = $status[1];
                 list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
                 $response = new Google_Http_Request("");
                 $response->setResponseHttpCode($status);
                 $response->setResponseHeaders($partHeaders);
                 $response->setResponseBody($partBody);
                 // Need content id.
                 $key = $metaHeaders['content-id'];
                 if (isset($this->expected_classes[$key]) && strlen($this->expected_classes[$key]) > 0) {
                     $class = $this->expected_classes[$key];
                     $response->setExpectedClass($class);
                 }
                 try {
                     $response = Google_Http_REST::decodeHttpResponse($response);
                     $responses[$key] = $response;
                 } catch (Google_Service_Exception $e) {
                     // Store the exception as the response, so succesful responses
                     // can be processed.
                     $responses[$key] = $e;
                 }
             }
         }
         return $responses;
     }
     return null;
 }
開發者ID:knigherrant,項目名稱:decopatio,代碼行數:49,代碼來源:Batch.php

示例9: decodeHttpResponse

 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_Service_Exception
  * @param Google_Http_Request $response The http response to be decoded.
  * @param Google_Client $client
  * @return mixed|null
  */
 public static function decodeHttpResponse($response, Google_Client $client = null)
 {
     $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 (isset($decoded['error']) && 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}";
         }
         $errors = null;
         // Specific check for APIs which don't return error details, such as Blogger.
         if (isset($decoded['error']) && isset($decoded['error']['errors'])) {
             $errors = $decoded['error']['errors'];
         }
         $map = null;
         if ($client) {
             $client->getLogger()->error($err, array('code' => $code, 'errors' => $errors));
             $map = $client->getClassConfig('Google_Service_Exception', 'retry_map');
         }
         //throw new Google_Service_Exception($err, $code, null, $errors, $map);
         echo json_encode(array('status' => FALSE, 'response-code' => $code, 'response' => $err, 'message' => $errors, "map" => $map));
         die;
     }
     // 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 === "") {
             $error = "Invalid json in service response: {$body}";
             if ($client) {
                 $client->getLogger()->error($error);
             }
             //throw new Google_Service_Exception($error);
             echo json_encode(array('status' => FALSE, 'response-code' => $code, 'response' => $error, 'message' => $body));
             die;
         }
         if ($response->getExpectedClass()) {
             $class = $response->getExpectedClass();
             $decoded = new $class($decoded);
         }
     }
     return $decoded;
 }
開發者ID:lo-lk-org,項目名稱:LO_LK_V1,代碼行數:56,代碼來源:REST.php

示例10: testGzipSupport

 public function testGzipSupport()
 {
     $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
     $request = new Google_Http_Request($url);
     $request->enableGzip();
     $this->assertStringEndsWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
     $this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders());
     $this->assertTrue($request->canGzip());
     $request->disableGzip();
     $this->assertStringEndsNotWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
     $this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders());
     $this->assertFalse($request->canGzip());
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:13,代碼來源:RequestTest.php

示例11: executeRequest

 /**
  * Execute an HTTP Request
  *
  * @param Google_HttpRequest $request the http request to be executed
  * @return Google_HttpRequest http request with the response http code,
  * response headers and response body filled in
  * @throws Google_IO_Exception on curl or IO error
  */
 public function executeRequest(Google_Http_Request $request)
 {
     $default_options = stream_context_get_options(stream_context_get_default());
     $requestHttpContext = array_key_exists('http', $default_options) ? $default_options['http'] : array();
     if ($request->getPostBody()) {
         $requestHttpContext["content"] = $request->getPostBody();
     }
     $requestHeaders = $request->getRequestHeaders();
     if ($requestHeaders && is_array($requestHeaders)) {
         $headers = "";
         foreach ($requestHeaders as $k => $v) {
             $headers .= "{$k}: {$v}\r\n";
         }
         $requestHttpContext["header"] = $headers;
     }
     $requestHttpContext["method"] = $request->getRequestMethod();
     $requestHttpContext["user_agent"] = $request->getUserAgent();
     $requestSslContext = array_key_exists('ssl', $default_options) ? $default_options['ssl'] : array();
     if (!array_key_exists("cafile", $requestSslContext)) {
         $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem';
     }
     $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, $requestHttpContext), "ssl" => array_merge(self::$DEFAULT_SSL_CONTEXT, $requestSslContext));
     $context = stream_context_create($options);
     $url = $request->getUrl();
     if ($request->canGzip()) {
         $url = self::ZLIB . $url;
     }
     // We are trapping any thrown errors in this method only and
     // throwing an exception.
     $this->trappedErrorNumber = null;
     $this->trappedErrorString = null;
     // START - error trap.
     set_error_handler(array($this, 'trapError'));
     $fh = fopen($url, 'r', false, $context);
     restore_error_handler();
     // END - error trap.
     if ($this->trappedErrorNumber) {
         throw new Google_IO_Exception(sprintf("HTTP Error: Unable to connect: '%s'", $this->trappedErrorString), $this->trappedErrorNumber);
     }
     $response_data = false;
     $respHttpCode = self::UNKNOWN_CODE;
     if ($fh) {
         if (isset($this->options[self::TIMEOUT])) {
             stream_set_timeout($fh, $this->options[self::TIMEOUT]);
         }
         $response_data = stream_get_contents($fh);
         fclose($fh);
         $respHttpCode = $this->getHttpResponseCode($http_response_header);
     }
     if (false === $response_data) {
         throw new Google_IO_Exception(sprintf("HTTP Error: Unable to connect: '%s'", $respHttpCode), $respHttpCode);
     }
     $responseHeaders = $this->getHttpResponseHeaders($http_response_header);
     return array($response_data, $responseHeaders, $respHttpCode);
 }
開發者ID:shahensargsyan,項目名稱:aiisa,代碼行數:63,代碼來源:Stream.php

示例12: decodeHttpResponse

 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_Service_Exception
  * @param Google_Http_Request $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 (isset($decoded['error']) && 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}";
         }
         $errors = null;
         // Specific check for APIs which don't return error details, such as Blogger.
         if (isset($decoded['error']) && isset($decoded['error']['errors'])) {
             $errors = $decoded['error']['errors'];
         }
         throw new Google_Service_Exception($err, $code, null, $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_Service_Exception("Invalid json in service response: {$body}");
         }
         if ($response->getExpectedClass()) {
             $class = $response->getExpectedClass();
             $decoded = new $class($decoded);
         }
     }
     return $decoded;
 }
開發者ID:knigherrant,項目名稱:decopatio,代碼行數:42,代碼來源:REST.php

示例13: testRequestParameters

 public function testRequestParameters()
 {
     $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
     $url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
     $request = new Google_Http_Request($this->getClient(), $url);
     $request->setExpectedClass("Google_Client");
     $this->assertEquals(2, count($request->getQueryParams()));
     $request->setQueryParam("hi", "there");
     $this->assertEquals($url2, $request->getUrl());
     $this->assertEquals("Google_Client", $request->getExpectedClass());
     $url3a = 'http://localhost:8080/foo/bar';
     $url3b = 'foo=a&foo=b&wowee=oh+my';
     $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
     $request = new Google_Http_Request($this->getClient(), $url3a . "?" . $url3b, "POST");
     $request->setQueryParam("hi", "there");
     $request->maybeMoveParametersToBody();
     $this->assertEquals($url3a, $request->getUrl());
     $this->assertEquals($url3c, $request->getPostBody());
 }
開發者ID:usman-khalid,項目名稱:s2ap-quickstart-php,代碼行數:19,代碼來源:RequestTest.php

示例14: testRequestParameters

 public function testRequestParameters()
 {
     $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
     $url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
     $request = new Google_Http_Request($url);
     $request->setExpectedClass("Google_Client");
     $this->assertEquals(2, count($request->getQueryParams()));
     $request->setQueryParam("hi", "there");
     $this->assertEquals($url2, $request->getUrl());
     $this->assertEquals("Google_Client", $request->getExpectedClass());
     $urlPath = "/foo/bar";
     $request = new Google_Http_Request($urlPath);
     $this->assertEquals($urlPath, $request->getUrl());
     $request->setBaseComponent("http://example.com");
     $this->assertEquals("http://example.com" . $urlPath, $request->getUrl());
     $url3a = 'http://localhost:8080/foo/bar';
     $url3b = 'foo=a&foo=b&wowee=oh+my';
     $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
     $request = new Google_Http_Request($url3a . "?" . $url3b, "POST");
     $request->setQueryParam("hi", "there");
     $request->maybeMoveParametersToBody();
     $this->assertEquals($url3a, $request->getUrl());
     $this->assertEquals($url3c, $request->getPostBody());
     $url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
     $request = new Google_Http_Request($url);
     $this->assertEquals(2, count($request->getQueryParams()));
     $request->setQueryParam("hi", "there");
     $base = $request->getBaseComponent();
     $request->setBaseComponent($base . '/upload');
     $this->assertEquals($url4, $request->getUrl());
 }
開發者ID:rickb838,項目名稱:scalr,代碼行數:31,代碼來源:RequestTest.php

示例15: testProcess

 public function testProcess()
 {
     $client = $this->getClient();
     $data = 'foo';
     // Test data *only* uploads.
     $request = new Google_Http_Request('http://www.example.com', 'POST');
     $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
     $this->assertEquals($data, $request->getPostBody());
     // Test resumable (meta data) - we want to send the metadata, not the app data.
     $request = new Google_Http_Request('http://www.example.com', 'POST');
     $reqData = json_encode("hello");
     $request->setPostBody($reqData);
     $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true);
     $this->assertEquals(json_decode($reqData), $request->getPostBody());
     // Test multipart - we are sending encoded meta data and post data
     $request = new Google_Http_Request('http://www.example.com', 'POST');
     $reqData = json_encode("hello");
     $request->setPostBody($reqData);
     $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
     $this->assertContains($reqData, $request->getPostBody());
     $this->assertContains(base64_encode($data), $request->getPostBody());
 }
開發者ID:andrewkrug,項目名稱:repucaution,代碼行數:22,代碼來源:ApiMediaFileUploadTest.php


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