コード例 #1
0
 public function request($path, $query_array = array(), $options = array())
 {
     $parse_url = parse_url($path);
     if (isset($parse_url['scheme']) && !empty($parse_url['scheme'])) {
         $validate_url = $path;
     } else {
         $validate_url = API_DOMAIN . $path;
     }
     $method = isset($options['method']) ? strtolower($options['method']) : 'get';
     $post_data = isset($options['post_data']) ? $options['post_data'] : array();
     $content_type = isset($options['content_type']) ? $options['content_type'] : 'form_params';
     $ssl_verify = isset($options['ssl_verify']) ? $options['ssl_verify'] : FALSE;
     $httpclient_options['verify'] = $ssl_verify;
     if ($method == 'post') {
         $httpclient_options[$content_type] = $post_data;
     }
     if ($query_array !== FALSE) {
         $validate_url .= '?' . LoginRadius::queryBuild(LoginRadius::authentication($query_array));
     }
     try {
         $response = \Drupal::httpClient()->{$method}($validate_url, $httpclient_options);
         $data = (string) $response->getBody();
         return $data;
     } catch (RequestException $e) {
         throw new LoginRadiusException($e->getMessage(), $e);
     } catch (ClientException $e) {
         throw new LoginRadiusException($e->getMessage(), $e);
     } catch (Exception $e) {
         throw new LoginRadiusException($e->getMessage(), $e);
     }
 }
コード例 #2
0
 /**
  * Access LoginRadius API server by fsockopen method
  *
  * @param type $request_url
  * @param type $options
  * @return type
  */
 private function fsockopenApiMethod($request_url, $options = array())
 {
     $ssl_verify = isset($options['ssl_verify']) ? $options['ssl_verify'] : false;
     $method = isset($options['method']) ? strtolower($options['method']) : 'get';
     $data = isset($options['post_data']) ? $options['post_data'] : array();
     $content_type = isset($options['content_type']) ? $options['content_type'] : 'form_params';
     if (!empty($data)) {
         $options = array('http' => array('method' => strtoupper($method), 'timeout' => 50, 'header' => 'Content-type :application/' . $content_type, 'content' => $content_type == 'json' ? json_encode($data) : LoginRadius::queryBuild($data)), "ssl" => array("verify_peer" => $ssl_verify));
         $context = stream_context_create($options);
     } else {
         $context = NULL;
     }
     $json_response = @file_get_contents($request_url, false, $context);
     if (!$json_response) {
         throw new LoginRadiusException('file_get_contents error');
     }
     return $json_response;
 }