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


PHP HttpClient::setMethod方法代码示例

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


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

示例1: getHttpClient

 /**
  * Set Google authentication credentials.
  * Must be done before trying to do any Google Data operations that
  * require authentication.
  * For example, viewing private data, or posting or deleting entries.
  *
  * @param string $email
  * @param string $password
  * @param string $service
  * @param \ZendGData\HttpClient $client
  * @param string $source
  * @param string $loginToken The token identifier as provided by the server.
  * @param string $loginCaptcha The user's response to the CAPTCHA challenge.
  * @param string $accountType An optional string to identify whether the
  * account to be authenticated is a google or a hosted account. Defaults to
  * 'HOSTED_OR_GOOGLE'. See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request
  * @throws \ZendGData\App\AuthException
  * @throws \ZendGData\App\HttpException
  * @throws \ZendGData\App\CaptchaRequiredException
  * @return \ZendGData\HttpClient
  */
 public static function getHttpClient($email, $password, $service = 'xapi', HttpClient $client = null, $source = self::DEFAULT_SOURCE, $loginToken = null, $loginCaptcha = null, $loginUri = self::CLIENTLOGIN_URI, $accountType = 'HOSTED_OR_GOOGLE')
 {
     if (!($email && $password)) {
         throw new App\AuthException('Please set your Google credentials before trying to ' . 'authenticate');
     }
     if ($client == null) {
         $client = new HttpClient();
     }
     // Build the HTTP client for authentication
     $client->setUri($loginUri);
     $client->setMethod('POST');
     $useragent = App::getUserAgentString($source);
     $client->setOptions(array('maxredirects' => 0, 'strictredirects' => true, 'useragent' => $useragent));
     $client->setEncType('multipart/form-data');
     $postParams = array('accountType' => $accountType, 'Email' => (string) $email, 'Passwd' => (string) $password, 'service' => (string) $service, 'source' => (string) $source);
     if ($loginToken || $loginCaptcha) {
         if ($loginToken && $loginCaptcha) {
             $postParams += array('logintoken' => (string) $loginToken, 'logincaptcha' => (string) $loginCaptcha);
         } else {
             throw new App\AuthException('Please provide both a token ID and a user\'s response ' . 'to the CAPTCHA challenge.');
         }
     }
     $client->setParameterPost($postParams);
     // Send the authentication request
     // For some reason Google's server causes an SSL error. We use the
     // output buffer to supress an error from being shown. Ugly - but works!
     ob_start();
     try {
         $response = $client->send();
     } catch (\Zend\Http\Client\Exception\ExceptionInterface $e) {
         throw new App\HttpException($e->getMessage(), $e);
     }
     ob_end_clean();
     // Parse Google's response
     $goog_resp = array();
     foreach (explode("\n", $response->getBody()) as $l) {
         $l = rtrim($l);
         if ($l) {
             list($key, $val) = explode('=', rtrim($l), 2);
             $goog_resp[$key] = $val;
         }
     }
     if ($response->getStatusCode() == 200) {
         $client->setClientLoginToken($goog_resp['Auth']);
         $useragent = App::getUserAgentString($source);
         $client->setOptions(array('strictredirects' => true, 'useragent' => $useragent));
         return $client;
     } elseif ($response->getStatusCode() == 403) {
         // Check if the server asked for a CAPTCHA
         if (array_key_exists('Error', $goog_resp) && $goog_resp['Error'] == 'CaptchaRequired') {
             throw new App\CaptchaRequiredException($goog_resp['CaptchaToken'], $goog_resp['CaptchaUrl']);
         } else {
             throw new App\AuthException('Authentication with Google failed. Reason: ' . (isset($goog_resp['Error']) ? $goog_resp['Error'] : 'Unspecified.'));
         }
     }
 }
开发者ID:hybridneo,项目名称:zendgdata,代码行数:77,代码来源:ClientLogin.php

示例2: sendRequest

 /**
  * send request to Smartling Service
  *
  * @param string $uri
  * @param array $requestData
  * @param string $method
  * @return string
  */
 protected function sendRequest($uri, $requestData, $method, $needUploadFile = false, $needUploadContent = false)
 {
     $connection = new HttpClient($this->_baseUrl . "/" . $uri, 443);
     $data['apiKey'] = $this->_apiKey;
     $data['projectId'] = $this->_projectId;
     $request = array_replace_recursive($data, $requestData);
     $connection->setMethod($method)->setNeedUploadFile($needUploadFile)->setNeedUploadContent($needUploadContent);
     if ($res = $connection->request($request)) {
         return $this->_response = $connection->getContent();
     } else {
         return new Exception("Can't connect to server");
     }
 }
开发者ID:mobiletulip,项目名称:smartling-api-sdk-php,代码行数:21,代码来源:SmartlingAPI.php

示例3: create

 public function create($url)
 {
     /*
     Static shortcut method to create and configure a new instance
     		of this class. Query is not automatically performed, but the
     		class is preconfigured so you can call doRequest() after
     		setting whatever other parameters you might need.
     (If you don't need to set any other parameters, you most likely
     		want one of the quickGet() or quickPost() methods instead.)
     */
     $bits = parse_url($url);
     $host = $bits['host'];
     $port = isset($bits['port']) ? $bits['port'] : 80;
     $path = isset($bits['path']) ? $bits['path'] : '/';
     if (isset($bits['query'])) {
         $path .= '?' . $bits['query'];
     }
     $client = new HttpClient($host, $port);
     $client->setPath($path);
     $client->setMethod("GET");
     return $client;
 }
开发者ID:hadinon,项目名称:cronos-api,代码行数:22,代码来源:HttpClient.class.php


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