mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-04 14:56:26 +00:00
Fix #120: json-encode request when request header Content-Type is application/json and data is a multidimensional array
This commit is contained in:
+9
-1
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user