5

I would like to pass an array through a http header.

Would it be acceptable to name multiple params the same name, and that way I would know that they belong to an array just like in a get request query string? Example:

CurrentHeaderArray: myarray[]=value1&myarray[]=value2&myarray[]=value3

There is already a stackoverflow answer to pass it through the query string of a get request, see this hyper link. How to pass an array within a query string?

Community
  • 1
  • 1
question_guy
  • 81
  • 1
  • 1
  • 5

2 Answers2

4

You can pass an array as string with some delimiter char as the way csv file does. Then, in the server side code, just use some string split function to get back the array. If the string contains the delimiter charater, escapes them.

VinhNT
  • 1,091
  • 8
  • 13
  • Simplifying this answer -- just pass your array values as a comma-delimited string (e.g. ['foo', 'bar'] -> my-header: "foo, bar") This is a pretty standard format, e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers – ericsoco Nov 13 '19 at 21:57
0

You can pass an array as a header like this:

CurrentHeaderArray : [ "value1", "value2", "value3" ]

You can easily try this in a tool like Fiddler, using the Composer.

seg
  • 1,398
  • 1
  • 11
  • 18