From 41c42faa0e17858a4d5ddc52085759d6cac99ec1 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 4 Dec 2014 22:35:39 -0800 Subject: [PATCH] Fix #95: Allow json data with PUT requests --- src/Curl/Curl.php | 2 +- tests/PHPCurlClass/PHPCurlClassTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 6b18036..58ca025 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -134,7 +134,7 @@ class Curl $this->url = $url; $this->setOpt(CURLOPT_URL, $this->url); $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT'); - $put_data = http_build_query($data); + $put_data = $this->postfields($data); if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { $this->setHeader('Content-Length', strlen($put_data)); } diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 5f4f351..f3917e1 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -269,6 +269,11 @@ class CurlTest extends PHPUnit_Framework_TestCase $this->assertEquals('key=value', $test->server('put', 'PUT', array( 'key' => 'value', ))); + + $test = new Test(); + $this->assertEquals('{"key":"value"}', $test->server('put', 'PUT', json_encode(array( + 'key' => 'value', + )))); } public function testPutFileHandle()