]> git.mxchange.org Git - friendica.git/commitdiff
Fix Guzzle InvalidArgumentException for POST with array parameters
authorPhilipp <admin@philipp.info>
Wed, 9 Nov 2022 21:17:31 +0000 (22:17 +0100)
committerPhilipp <admin@philipp.info>
Wed, 9 Nov 2022 21:25:37 +0000 (22:25 +0100)
src/Network/HTTPClient/Capability/ICanSendHttpRequests.php
src/Network/HTTPClient/Client/HttpClient.php
src/Network/HTTPClient/Client/HttpClientOptions.php

index fb51995b3b42057f522dc904871c06e64e834aa4..7c61b06cfad0c6664382138eccc9c828e17d0d01 100644 (file)
@@ -92,7 +92,7 @@ interface ICanSendHttpRequests
         * Send POST request to an URL
         *
         * @param string $url            URL to post
-        * @param mixed  $params         array of POST variables
+        * @param mixed  $params         POST variables (if an array is passed, it will automatically set as formular parameters)
         * @param array  $headers        HTTP headers
         * @param int    $timeout        The timeout in seconds, default system config value or 60 seconds
         *
@@ -107,6 +107,7 @@ interface ICanSendHttpRequests
         * @param string $url            Url to send to
         * @param array  $opts           (optional parameters) associative array with:
         *                                    'body' => (mixed) setting the body for sending data
+        *                                    'form_params' => (array) Associative array of form field names to values
         *                                'accept_content' => (string array) supply Accept: header with 'accept_content' as the value
         *                                'timeout' => int Timeout in seconds, default system config value or 60 seconds
         *                                'cookiejar' => path to cookie jar file
index 7974965ac3740ffb14efa48c854dbd07a5d634ce..cfc8fbfab1f0f3667f95e5a3a323dff9bd6f7860 100644 (file)
@@ -140,6 +140,10 @@ class HttpClient implements ICanSendHttpRequests
                        $conf[RequestOptions::BODY] = $opts[HttpClientOptions::BODY];
                }
 
+               if (!empty($opts[HttpClientOptions::FORM_PARAMS])) {
+                       $conf[RequestOptions::FORM_PARAMS] = $opts[HttpClientOptions::FORM_PARAMS];
+               }
+
                if (!empty($opts[HttpClientOptions::AUTH])) {
                        $conf[RequestOptions::AUTH] = $opts[HttpClientOptions::AUTH];
                }
@@ -205,7 +209,11 @@ class HttpClient implements ICanSendHttpRequests
        {
                $opts = [];
 
-               $opts[HttpClientOptions::BODY] = $params;
+               if (!is_array($params)) {
+                       $opts[HttpClientOptions::BODY] = $params;
+               } else {
+                       $opts[HttpClientOptions::FORM_PARAMS] = $params;
+               }
 
                if (!empty($headers)) {
                        $opts[HttpClientOptions::HEADERS] = $headers;
index 9a9ee772afa45e758b2ac95a30dc0a04ef07c011..f5ab4c9fb91fc7f882865fa5ede4a3e11e3bcce4 100644 (file)
@@ -59,9 +59,13 @@ class HttpClientOptions
        const VERIFY = 'verify';
 
        /**
-        * body: (mixed) Setting the body for sending data
+        * body: (string) Setting the body for sending data
         */
        const BODY = RequestOptions::BODY;
+       /**
+        * form_params: (array) Associative array of form field names to values
+        */
+       const FORM_PARAMS = RequestOptions::FORM_PARAMS;
        /**
         * auth: (array) Authentication settings for specific requests
         */