Added support for JSON strings instead of an array of POST parameters
authorAlexander Ebert <ebert@woltlab.com>
Mon, 30 Sep 2013 17:38:50 +0000 (19:38 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 30 Sep 2013 17:38:50 +0000 (19:38 +0200)
Fixes #1521

wcfsetup/install/files/lib/util/HTTPRequest.class.php

index 9bd8b8689c96b083f532b86a5dc3965cb4a839f0..1277f7251e5ec0db1087afe24de074ce508c2777 100644 (file)
@@ -109,10 +109,10 @@ final class HTTPRequest {
         * 
         * @param       string          $url            URL to connect to
         * @param       array<string>   $options
-        * @param       array           $postParameters Parameters to send via POST
+        * @param       mixed           $postParameters Parameters to send via POST
         * @param       array           $files          Files to attach to the request
         */
-       public function __construct($url, array $options = array(), array $postParameters = array(), array $files = array()) {
+       public function __construct($url, array $options = array(), $postParameters = array(), array $files = array()) {
                $this->setURL($url);
                
                $this->postParameters = $postParameters;
@@ -126,7 +126,13 @@ final class HTTPRequest {
                $this->addHeader('Accept-Language', WCF::getLanguage()->getFixedLanguageCode());
                if ($this->options['method'] !== 'GET') {
                        if (empty($this->files)) {
-                               $this->body = http_build_query($this->postParameters, '', '&');
+                               if (is_array($postParameters)) {
+                                       $this->body = http_build_query($this->postParameters, '', '&');
+                               }
+                               else if (is_string($postParameters) && !empty($postParameters)) {
+                                       $this->body = $postParameters;
+                               }
+                               
                                $this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
                        }
                        else {