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


PHP HttpClient::setConfig方法代码示例

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


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

示例1: sendRequest

 /**
  * @param RequestAbstract $request
  * @param string $endpointUrl
  * @return \Guzzle\Http\EntityBodyInterface|string
  * @throws Exception\ConnectionError
  */
 private function sendRequest(RequestAbstract $request, $endpointUrl)
 {
     $client = new HttpClient();
     $client->setConfig(array('curl.options' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
     $httpRequest = $client->post($endpointUrl, null, $request->getRawData());
     try {
         return $httpRequest->send()->getBody();
     } catch (RequestException $e) {
         throw new ConnectionError($e->getMessage());
     }
 }
开发者ID:paranoiaproject,项目名称:payuclient,代码行数:17,代码来源:Client.php

示例2: 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 \Zend\GData\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 \Zend\GData\App\AuthException
     * @throws \Zend\GData\App\HttpException
     * @throws \Zend\GData\App\CaptchaRequiredException
     * @return \Zend\GData\HttpClient
     */
    public static function getHttpClient($email, $password, $service = 'xapi',
        $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();
        }
        
        if (!$client instanceof \Zend\Http\Client) {
            throw new App\HttpException(
                    'Client is not an instance of Zend\Http\Client.');
        }

        // Build the HTTP client for authentication
        $client->setUri($loginUri);
        $client->setMethod('POST');
        $useragent = $source . ' Zend_Framework_Gdata/' . \Zend\Version::VERSION;
        $client->setConfig(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 $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 = $source . ' Zend_Framework_Gdata/' . \Zend\Version::VERSION;
//.........这里部分代码省略.........
开发者ID:rickogden,项目名称:zf2,代码行数:101,代码来源:ClientLogin.php


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