本文整理汇总了PHP中HttpSocket::configAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpSocket::configAuth方法的具体用法?PHP HttpSocket::configAuth怎么用?PHP HttpSocket::configAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpSocket
的用法示例。
在下文中一共展示了HttpSocket::configAuth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index() {
$HttpSocket = new HttpSocket ();
if (sizeof ( $this->params ['pass'] [0] ) != 1) {
throw new InvalidArgumentException ();
}
if (! empty ( $_SERVER ['PHP_AUTH_USER'] ) && ! empty ( $_SERVER ['PHP_AUTH_PW'] )) {
$HttpSocket->configAuth ( 'Basic', $_SERVER ['PHP_AUTH_USER'], $_SERVER ['PHP_AUTH_PW'] );
} elseif (isset ( $this->CurrentUser )) {
$HttpSocket->configAuth ( 'Basic', $this->Session->read ( 'Auth.User.Login' ), $this->Session->read ( 'Auth.User.Password' ) );
}
$this->response->type ( 'json' );
$request = array (
'method' => env ( 'REQUEST_METHOD' ),
'body' => $this->request->data,
'uri' => array (
'scheme' => Configure::read ( 'Api.scheme' ),
'host' => Configure::read ( 'Api.host' ),
'port' => 80,
'path' => Configure::read ( 'Api.path' ) . $this->params ['pass'] [0],
'query' => $this->params->query
)
);
$response = $HttpSocket->request ( $request );
$this->response->statusCode ( $response->code );
$this->response->body ( $response->body );
return $this->response;
}
示例2: request
/**
* Submits a request to Stripe. Requests are merged with default values, such as
* the api host. If an error occurs, it is stored in `$lastError` and `false` is
* returned.
*
* @param array $request Request details
* @return mixed `false` on failure, data on success
*/
public function request($request = array())
{
$this->lastError = null;
$this->request = array('uri' => array('host' => 'api.stripe.com', 'scheme' => 'https', 'path' => '/'), 'method' => 'GET');
$this->request = Set::merge($this->request, $request);
$this->request['uri']['path'] = '/v1/' . trim($this->request['uri']['path'], '/');
$this->Http->configAuth('Basic', $this->config['api_key'], '');
try {
$response = $this->Http->request($this->request);
switch ($this->Http->response['status']['code']) {
case '200':
return json_decode($response, true);
break;
case '400':
$error = json_decode($response, true);
$this->lastError = $error['error']['message'];
return false;
break;
case '402':
$error = json_decode($response, true);
$this->lastError = $error['error']['message'];
return false;
break;
default:
$this->lastError = 'Unexpected error.';
CakeLog::write('stripe', $this->lastError);
return false;
break;
}
} catch (CakeException $e) {
$this->lastError = $e->message;
CakeLog::write('stripe', $e->message);
}
}
示例3: _request
protected function _request($method, $params = array(), $request = array())
{
// preparing request
$query = Hash::merge(array('method' => $method, 'format' => 'json'), $params);
$request = Hash::merge($this->_request, array('uri' => array('query' => $query)), $request);
// Read cached GET results
if ($request['method'] == 'GET') {
$cacheKey = $this->_generateCacheKey();
$results = Cache::read($cacheKey);
if ($results !== false) {
return $results;
}
}
// createding http socket object with auth configuration
$HttpSocket = new HttpSocket();
$HttpSocket->configAuth('OauthLib.Oauth', array('Consumer' => array('consumer_token' => $this->_config['key'], 'consumer_secret' => $this->_config['secret']), 'Token' => array('token' => $this->_config['token'], 'secret' => $this->_config['secret2'])));
// issuing request
$response = $HttpSocket->request($request);
// olny valid response is going to be parsed
if ($response->code != 200) {
if (Configure::read('debugApis')) {
debug($request);
debug($response->body);
}
return false;
}
// parsing response
$results = $this->_parseResponse($response);
// cache and return results
if ($request['method'] == 'GET') {
Cache::write($cacheKey, $results);
}
return $results;
}
示例4: _getServerInformation
/**
* Retrieve information about the authentication
*
* @param HttpSocket $http Http socket instance.
* @param array &$authInfo Authentication info.
* @return bool
*/
protected static function _getServerInformation(HttpSocket $http, &$authInfo)
{
$originalRequest = $http->request;
$http->configAuth(false);
$http->request($http->request);
$http->request = $originalRequest;
$http->configAuth('Digest', $authInfo);
if (empty($http->response['header']['WWW-Authenticate'])) {
return false;
}
preg_match_all('@(\\w+)=(?:(?:")([^"]+)"|([^\\s,$]+))@', $http->response['header']['WWW-Authenticate'], $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$authInfo[$match[1]] = $match[2];
}
if (!empty($authInfo['qop']) && empty($authInfo['nc'])) {
$authInfo['nc'] = 1;
}
return true;
}