Fix #120: json-encode request when request header Content-Type is application/json and data is a multidimensional array

This commit is contained in:
Zach Borboa
2015-01-17 02:00:25 -08:00
parent ec8b7825aa
commit 891a66c327
2 changed files with 20 additions and 1 deletions
+9 -1
View File
@@ -413,7 +413,15 @@ class Curl
{
if (is_array($data)) {
if (self::is_array_multidim($data)) {
$data = self::http_build_multi_query($data);
if (isset($this->headers['Content-Type']) &&
preg_match($this->json_pattern, $this->headers['Content-Type'])) {
$json_str = json_encode($data);
if (!($json_str === false)) {
$data = $json_str;
}
} else {
$data = self::http_build_multi_query($data);
}
} else {
$binary_data = false;
foreach ($data as $key => $value) {
+11
View File
@@ -652,6 +652,17 @@ class CurlTest extends PHPUnit_Framework_TestCase
),
'{"key":"value"}',
),
array(
array(
'key' => 'value',
'strings' => array(
'a',
'b',
'c',
),
),
'{"key":"value","strings":["a","b","c"]}',
),
) as $test) {
list($data, $expected_response) = $test;