本文整理汇总了PHP中HttpClient::request方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::request方法的具体用法?PHP HttpClient::request怎么用?PHP HttpClient::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::request方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: valid
/**
* {@inheritdoc}
*/
public function valid()
{
if (!isset($this->result[$this->offset]) && $this->offset < $this->max) {
++$this->current;
$url = preg_replace('/page=[0-9]+/', 'page=' . $this->current, $this->url);
$result = $this->client->request($this->method, $url, $this->params);
$this->result = array_merge($this->result, $result[$this->key]);
return true;
}
return $this->offset < $this->max;
}
示例2: message_put
public function message_put($proxy_at, $from, $body, $srv_addr, $srv_at, $mod_params)
{
$channelId = 1;
$priority = 100;
$text = $body;
$url = 'http://botq.localhost/api/textMessage/' . $channelId . '/' . $priority . '/' . urlencode($text);
$hc = new \HttpClient();
$hc->request($url);
}
示例3: _checkUser
protected function _checkUser()
{
if (fnGet($this->input, 'access_token') == '') {
$this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '参数[access_token]不能为空'), 400);
}
// 设置当前用户和客户端
$this->session->setUser($user = new User())->setClient($client = new Client());
$passportConfig = $this->config->get("api.passport");
// 尝试从缓存获取 userInfo
if ($this->_userInfo = S($cacheKey = 'access_token_info.' . fnGet($this->input, 'access_token'))) {
$user->find(fnGet($this->_userInfo, 'user_id'));
$client->find(fnGet($this->_userInfo, 'client_id'));
return;
}
// 向 passport 请求 userInfo
$time = time();
$url = str_replace('internal-resource/user-info?', '', $passportConfig->passportUrl) . 'internal-resource/user-info';
$params = array('access_token' => fnGet($this->input, 'access_token'), 'app' => $passportConfig->passportApp, 'time' => $time);
$sign = md5(implode('', $params) . $passportConfig->passportSecret);
$params['sign'] = $sign;
$http = new HttpClient();
$response = $http->request($url, $params);
$data = json_decode($response, true);
if (fnGet($data, 'id')) {
//检测用户是否已经保存
$user->getByUsername($username = fnGet($data, 'username'));
if (!($userId = $user->getId()) || !$user->getData('passport_id') || $user->getData('mobile') != fnGet($data, 'mobile')) {
$user->addData(array('username' => $username, 'email' => fnGet($data, 'email'), 'mobile' => fnGet($data, 'mobile'), 'passport_id' => fnGet($data, 'passport_id'), 'avatar' => fnGet($data, 'avatar'), 'nickname' => fnGet($data, 'nickname')));
$user->save();
$userId = $user->getId();
}
//检测客户端是否已经保存
$client->getByAppId($appId = fnGet($data, 'client_info/id'));
if (!($clientId = $client->getId()) || $client->getScopes() != fnGet($data, 'client_info/scopes')) {
$client->addData(array('client' => $appId, 'name' => fnGet($data, 'client_info/name'), 'app_secret' => fnGet($data, 'client_info/secret'), 'developerurl' => fnGet($data, 'client_info/endpoint'), 'scopes' => fnGet($data, 'client_info/scopes')));
$client->save();
$clientId = $client->getId();
}
$this->_userInfo = array('user_id' => $userId, 'client_id' => $clientId, 'username' => $username, 'session_data' => fnGet($data, 'session_data'));
S($cacheKey, $this->_userInfo, 3600);
return;
}
$this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '用户无效'), 400);
}
示例4: post
function post($host, $data, $timeout = 5)
{
return HttpClient::request($host, $data, 'POST', $timeout);
}
示例5: 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");
}
}
示例6: 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);
$useragent = $source . ' Zend_Framework_Gdata/' . \Zend\Version::VERSION;
$client->setConfig(array('maxredirects' => 0, 'strictredirects' => true, 'useragent' => $useragent));
$client->setParameterPost('accountType', $accountType);
$client->setParameterPost('Email', (string) $email);
$client->setParameterPost('Passwd', (string) $password);
$client->setParameterPost('service', (string) $service);
$client->setParameterPost('source', (string) $source);
if ($loginToken || $loginCaptcha) {
if ($loginToken && $loginCaptcha) {
$client->setParameterPost('logintoken', (string) $loginToken);
$client->setParameterPost('logincaptcha', (string) $loginCaptcha);
} else {
throw new App\AuthException('Please provide both a token ID and a user\'s response ' . 'to the CAPTCHA challenge.');
}
}
// 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->request('POST');
} 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->getStatus() == 200) {
$client->setClientLoginToken($goog_resp['Auth']);
$useragent = $source . ' Zend_Framework_Gdata/' . \Zend\Version::VERSION;
$client->setConfig(array('strictredirects' => true, 'useragent' => $useragent));
return $client;
} elseif ($response->getStatus() == 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.'));
}
}
}
示例7: request
/**
* {@inheritdoc}
*/
public function request($method, $path, $body = null, array $options = [])
{
$authorizationHeader = $this->isTokenAuthentication() ? $this->getTokenAuthorizationString() : $this->getBasicAuthorizationString();
$options = array_merge_recursive(['headers' => ['Authorization' => $authorizationHeader]], $options);
return $this->httpClient->request($method, $path, $body, $options);
}
示例8: get
protected function get($uri, $params = array())
{
$params = array_merge($params, array('from' => $this->getFrom(), 'user' => $this->getUser(), 'pass' => $this->getPass()));
$url = self::ENDPOINT . $uri . '?' . http_build_query($params);
$httpClient = $this->getHttpClient();
if (null === $httpClient) {
$httpClient = new HttpClient();
}
return $httpClient->request($url);
}