示例#1
0
 public static function SingleRequest($url, $data = false, $type = "GET", $extra_options = false)
 {
     $response = false;
     if ($type === "GET" && $data !== false) {
         $query = http_build_query($data);
         if (strpos($url, "?")) {
             $url = "{$url}&{$query}";
         } else {
             $url = "{$url}?{$query}";
         }
         $data = false;
     }
     $options = ['url' => $url, "post_data" => $data, "callback" => function (Response $result) use(&$response) {
         $response = $result;
     }];
     if (is_array($extra_options)) {
         foreach ($extra_options as $key => $val) {
             $options[$key] = $val;
         }
     }
     $http = new Requests();
     $http->addRequest($options, false);
     $http->execute();
     return $response;
 }