I know this post is really old, but I have to reply because although BalusC's answer is marked as correct, it's not completely correct.

You have to write the query adding "[]" to foo like this:

foo[]=val1&foo[]=val2&foo[]=val3
Answer from user1922543 on Stack Overflow
Top answer
1 of 3
224

I know this post is really old, but I have to reply because although BalusC's answer is marked as correct, it's not completely correct.

You have to write the query adding "[]" to foo like this:

foo[]=val1&foo[]=val2&foo[]=val3
2 of 3
185

That depends on what the target server accepts. There is no definitive standard for this. See also a.o. Wikipedia: Query string:

While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. field1=value1&field1=value2&field2=value3).[4][5]

Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.

foo=value1&foo=value2&foo=value3
String[] foo = request.getParameterValues("foo"); // [value1, value2, value3]

The request.getParameter("foo") will also work on it, but it'll return only the first value.

String foo = request.getParameter("foo"); // value1

And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.

foo[]=value1&foo[]=value2&foo[]=value3
_GET["foo"]; // [value1, value2, value3]
echo is_array($foo); // true

In case you still use foo=value1&foo=value2&foo=value3, then it'll return only the first value.

_GET["foo"]; // value1
echo is_array($foo); // false

Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you'd need to use the exact parameter name including the braces.

String[] foo = request.getParameterValues("foo[]"); // [value1, value2, value3]
🌐
Elixir Forum
elixirforum.com › t › http-get-request-with-array-argument › 46182
HTTP GET request with array argument | Elixir Forum
February 21, 2022 - Try option c, it should be supported by default in Phoenix IIRC. You should be able to find the array in the request params like %{"ids" => ["12bb23d2...", "654802aa..."]}.
Discussions

Array Parameter in GET request
I need to send a GET request for weather data. One of the parameters is a list. If I send a single value in that parameter, all is well. As soon as I add another value, I get an error message. (The full link works 100% in postman. I presume Bubble works a bit different) Any advice? More on forum.bubble.io
🌐 forum.bubble.io
2
0
February 28, 2023
Sending Array Of Objects in GET request (axios)
Now I know when we want to send complex params in query we use POST method This is incorrect. You should use POST when you are adding something to a collection. If you are only retrieving data, you should still use GET. I say that knowing full well that GraphQL totally ignores that notion, but that's Facebook for you. I also don't get why you need filter to be an array of objects? Do you have an example of when the array would have many indices? I'd expect you want a GET with a query string that's something like ?name=descriptive&value=test but maybe you're not in control of your backend? IDK. qs handles query strings, not POST bodies, which (presumably) are stringified JSON. So if you're set on doing a POST with a body, you want JSON.stringify More on reddit.com
🌐 r/reactjs
11
7
April 21, 2022
How to pass array as a parameter
However, given the way you are trying to use your site ID in the request, you generally cannot pass an array as a URL Parameter. More on community.postman.com
🌐 community.postman.com
4
0
June 25, 2020
HTTP request with array body parameter
Issue So, I need to send a HTTP request with a body parameter named items with the item inside which in turn has the parameters name and price of that specific item. It must be an array. I can’t get this specific part to… More on community.n8n.io
🌐 community.n8n.io
3
0
March 13, 2023
Top answer
1 of 11
682

Here's what I figured out:

Submitting multi-value form fields, i.e. submitting arrays through GET/POST vars, can be done several different ways, as a standard is not necessarily spelled out.

Three possible ways to send multi-value fields or arrays would be:

  • ?cars[]=Saab&cars[]=Audi (Best way- PHP reads this into an array)
  • ?cars=Saab&cars=Audi (Bad way- PHP will only register last value)
  • ?cars=Saab,Audi (Haven't tried this)

Form Examples

On a form, multi-valued fields could take the form of a select box set to multiple:

<form> 
    <select multiple="multiple" name="cars[]"> 
        <option>Volvo</option> 
        <option>Saab</option> 
        <option>Mercedes</option> 
    </select>
</form>

(NOTE: In this case, it would be important to name the select control some_name[], so that the resulting request vars would be registered as an array by PHP)

... or as multiple hidden fields with the same name:

<input type="hidden" name="cars[]" value="Volvo">
<input type="hidden" name="cars[]" value="Saab">
<input type="hidden" name="cars[]" value="Mercedes">

NOTE: Using field[] for multiple values is really poorly documented. I don't see any mention of it in the section on multi-valued keys in Query string - Wikipedia, or in the W3C docs dealing with multi-select inputs.


UPDATE

As commenters have pointed out, this is very much framework-specific. Some examples:

Query string:

?list_a=1&list_a=2&list_a=3&list_b[]=1&list_b[]=2&list_b[]=3&list_c=1,2,3

Rails:

"list_a": "3", 
"list_b":[
    "1",
    "2",
    "3"
  ], 
"list_c": "1,2,3"

Angular:

 "list_a": [
    "1",
    "2",
    "3"
  ],
  "list_b[]": [
    "1",
    "2",
    "3"
  ],
  "list_c": "1,2,3"

(Angular discussion)

See comments for examples in node.js, Wordpress, ASP.net


Maintaining order: One more thing to consider is that if you need to maintain the order of your items (i.e. array as an ordered list), you really only have one option, which is passing a delimited list of values, and explicitly converting it to an array yourself.

2 of 11
49

A query string carries textual data so there is no option but to explode the array, encode it correctly and pass it in a representational format of your choice:

p1=value1&pN=valueN...
data=[value1,...,valueN]
data={p1:value1,...,pN:valueN}

and then decode it in your server side code.

🌐
Bubble
forum.bubble.io › need help › apis
Array Parameter in GET request - APIs - Bubble Forum
February 28, 2023 - I need to send a GET request for weather data. One of the parameters is a list. If I send a single value in that parameter, all is well. As soon as I add another value, I get an error message. (The full link works 100% i…
🌐
Reddit
reddit.com › r/reactjs › sending array of objects in get request (axios)
r/reactjs on Reddit: Sending Array Of Objects in GET request (axios)
April 21, 2022 -

I'm implementing filter, sorting, pagination and search functionality via API call. For filter values i have to send array of objects in parameters.

Now I know when we want to send complex params in query we use POST method. But still wants to understand.

In my application, swagger stringify does it without any issue. I can't get the same format which is as below.

e g. This is i want in request headers (payload)

filter:[{name:"descriptive", value: "test"}]

I have tried qs package and JSON.stringify

qs.stringify(params)

or with arrayFormat but not getting the above format in payload.

Instead I'm getting this, which is not acceptable

filter[0][name]: descriptive

filter[0][value]: test

any help would be appreciated.

🌐
GitHub
gist.github.com › and1truong › d78628970ca895b6e9f49f92fa893c3b
What is the best practice for passing an array of strings as query parameters in an HTTP request, and how can it be effectively parsed on the server side? · GitHub
Use request.args.getlist('my_array') to retrieve the list of values. ... Use req.query.my_array to access the array of values. ... Use @RequestParam(value = "my_array", required = false) and specify List<String> as the parameter type.
🌐
Brian Childress
brianchildress.co › sending-array-of-values-in-get-request
Sending an Array of Values in a GET Request - Brian Childress
February 15, 2022 - Sometimes you might need to send multiple values for a given parameter in a GET request to your API. For example, you have a GET /users API endpoint and you want to lookup information on several users at once. You might want your query to look something like: /users?username=bob;sally;john.
🌐
Medium
medium.com › raml-api › arrays-in-query-params-33189628fa68
Arrays in query params. The same way there is no concensus over… | by Jonathan Stoikovitch | RAML by Example | Medium
November 4, 2020 - Let’s see how different groups of people have thought about formating that fields query parameter. And for each use-case, we'll see how to model that query parameter in RAML. A client MAY request that an endpoint return only specific fields in the response on a per-type basis by including a fields[TYPE] parameter.
Find elsewhere
🌐
YouTrack Support
youtrack-support.jetbrains.com › hc › en-us › community › posts › 360010685319-Send-an-array-parameter-in-GET-HTTP-request-using-workflow
Send an array parameter in GET HTTP request using workflow – YouTrack Support | JetBrains
I have to make HTTP GET request like this: tasks.task.get&select[]=TITLE&select[]=DESCRIPTION&select[]=RESPONSIBLE_ID&select[]=PRIORITY&select[]=STATUS&select[]=DEADLINE&select[]=PARENT_ID&select[]=UF_YOUTRACK_ID&select[]=UF_UPDATED_BY_YT&select[]=UF_COMMENT_UPDATED_BY_YT&select[]=UF_YT_TYPE_OF_WORK&select[]=UF_AUTO_218204594690 documentation says that every param must be a string, and couldn't find better way then this wrong way: ```js connection.getSync( "tasks.task.get", { 'taskId': bx_id, 'select': 'TITLE', 'select': 'DESCRIPTION', 'select': 'RESPONSIBLE_ID', 'select': 'PRIORITY', 'select'
🌐
Himynameistim
himynameistim.com › blog › array-parameter-in-webapi-get-re
Array parameter in WebAPI Get Request - Tim
November 23, 2022 - The solution will now run even with multiple array parameters, and swagger will also pick up that these are query-string array parameters and give you the option to add individual items when you test a request.
🌐
Postman
community.postman.com › help hub
How to pass array as a parameter - Help Hub - Postman Community
June 25, 2020 - So yes, you would create the array of site_ids in your pre-request script. Or, if you already know these site ids ahead of time, you can place them in an environment variable in json format.
🌐
Medium
imvikaskohli.medium.com › what-are-the-functions-of-http-query-params-how-to-send-an-array-in-the-get-request-in-angular-828ede62acc2
What are the functions of HTTP query params, how to send an array in the Get Request in Angular? | by Vikas Kohli | Medium
January 10, 2021 - Syntax set(param: string, value: string) let queryParams = new HttpParams(); // queryParams.set(keyname, keyvalue) queryParams.set(user,'vikas'); queryParams.set(id,'1') //make sure you're sedning string values if not string then use toSTring ...
🌐
n8n
community.n8n.io › questions
HTTP request with array body parameter - Questions - n8n Community
March 13, 2023 - Issue So, I need to send a HTTP request with a body parameter named items with the item inside which in turn has the parameters name and price of that specific item. It must be an array. I can’t get this specific part to work. The structure should be something like this: [ { "items": { "product": { "price": 123, "name": "Robot" } } } ] Here is the API which I’m trying to use: https://hyros.docs.apiary.io/#reference/0/orders/create-order I don’t need b...
🌐
GitHub
gist.github.com › alexandru-calinoiu › 451bb7cdaa1e67111ae7
Send a CURL get request with an array param · GitHub
not working for me i ave to send a get request through curl with array parameter with a name[0]=value1&name[1]=value2 how should i do it can u help
🌐
Bubble
forum.bubble.io › need help
Sending an array of things in query parameter - Need help - Bubble Forum
December 7, 2022 - I’ve used query parameters and “Get data from page URL” to send an object ID to another page. I’m wondering if it’s possible to send an array of things to another page, and if so what format do I need to use? I tried ?things=id,id,id and that didn’t work for me.
🌐
PHP
php.net › manual › en › function.http-build-query.php
PHP: http_build_query - Manual
Params with null value do not present in result string. <?php $arr = array('test' => null, 'test2' => 1); echo http_build_query($arr); ?> will produce: test2=1 ... Passing null to $arg_separator is the same as passing an empty string, which is probably not what you want. If you need to change the enc_type, use this: http_build_query($query, null, '&', PHP_QUERY_RFC3986); Or possibly this: http_build_query($query, null, ini_get('arg_separator.output'), PHP_QUERY_RFC3986); But not this: // BAD CODE!
🌐
Derekhassan
derekhassan.dev › blog › how-to-pass-an-array-as-a-query-string-to-express
How to Pass an Array as a Query String to Express
I tried this with the Node Express server I was working with, and it turns out Express will automatically parse this as an array for you! Let's take an example. Fall is approaching and what better example to use than apples? Let's say we have an /apples endpoint that allows us to filter on different apple varieties to find price and stock. Here is a simple Express route that handles this request: app.get('/apples', (req, res) => { const apples = [ { type: 'Empire', price: '$1.20', quantityAvailable: 10, }, { type: 'Granny Smith', price: '$0.85', quantityAvailable: 8, }, { type: 'Gala', price:
🌐
Medium
medium.com › @gztxdy › the-axios-get-request-passes-in-an-array-of-parameters-83d6ece23c03
The axios get request passes in an array of parameters | by OrangeChu | Medium
December 6, 2023 - The axios get request passes in an array of parameters The general way axios sends get requests is as follows. axios.get(url,{params:{ a:1 }}) However, the above method can cause problems if the …