summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/io/http_client.cpp22
-rw-r--r--doc/classes/HTTPClient.xml6
2 files changed, 27 insertions, 1 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 6e4931f34b..c787b7ec4c 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -618,7 +618,27 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
String query = "";
Array keys = p_dict.keys();
for (int i = 0; i < keys.size(); ++i) {
- query += "&" + String(keys[i]).percent_encode() + "=" + String(p_dict[keys[i]]).percent_encode();
+ String encoded_key = String(keys[i]).percent_encode();
+ Variant value = p_dict[keys[i]];
+ switch (value.get_type()) {
+ case Variant::ARRAY: {
+ // Repeat the key with every values
+ Array values = value;
+ for (int j = 0; j < values.size(); ++j) {
+ query += "&" + encoded_key + "=" + String(values[j]).percent_encode();
+ }
+ break;
+ }
+ case Variant::NIL: {
+ // Add the key with no value
+ query += "&" + encoded_key;
+ break;
+ }
+ default: {
+ // Add the key-value pair
+ query += "&" + encoded_key + "=" + String(value).percent_encode();
+ }
+ }
}
query.erase(0, 1);
return query;
diff --git a/doc/classes/HTTPClient.xml b/doc/classes/HTTPClient.xml
index 5bd7c4cd3e..018b548ef1 100644
--- a/doc/classes/HTTPClient.xml
+++ b/doc/classes/HTTPClient.xml
@@ -111,6 +111,12 @@
String queryString = httpClient.query_string_from_dict(fields)
returns:= "username=user&amp;password=pass"
[/codeblock]
+ Furthermore, if a key has a null value, only the key itself is added, without equal sign and value. If the value is an array, for each value in it a pair with the same key is added.
+ [codeblock]
+ var fields = {"single": 123, "not_valued": null, "multiple": [22, 33, 44]}
+ String queryString = httpClient.query_string_from_dict(fields)
+ returns:= "single=123&amp;not_valued&amp;multiple=22&amp;multiple=33&amp;multiple=44"
+ [/codeblock]
</description>
</method>
<method name="read_response_body_chunk">