Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Volkov committed Jul 6, 2016
1 parent 467ad2f commit 1e5f457
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/SimpleRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private static function makeRequest($url, $method = self::METHOD_GET, $params =

private static function prepareOpts($url, $method, $params, $headers, $username, $pass)
{
$json = false;
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
Expand All @@ -40,6 +41,7 @@ private static function prepareOpts($url, $method, $params, $headers, $username,
//prepare headers
foreach ($headers as $key => $header) {
$opts[CURLOPT_HTTPHEADER][] = "$key:$header";
if (strpos($header, "application/json") !== false) $json = true;
}

//prepare get params
Expand All @@ -52,7 +54,8 @@ private static function prepareOpts($url, $method, $params, $headers, $username,
if ($method == self::METHOD_POST && !empty($params)) {
$opts[CURLOPT_POST] = true;
if (is_array($params)) {
$params_str = json_encode($params);
$params_str = http_build_query($params, '', '&');
if ($json) $params_str = json_encode($params);
} else {
$params_str = $params;
}
Expand Down

0 comments on commit 1e5f457

Please sign in to comment.