8

What RFC defines the passing arrays over HTTP? Most web application platforms allow you to supply an array of arguments over GET or POST. The following URL is an example:

http://localhost/?var[1]=one&var[2]=two&var[3]=three

RFC1738 defines URLs, however the bracket is missing from the Backus–Naur Form(BNF) definition of the URL. Also this RFC doesn't cover POST. Ideally I would like to get the BNF for this feature as defined in the RFC.

rook
  • 66,304
  • 38
  • 162
  • 239

2 Answers2

6

According to Wikipedia, there is no single spec:

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

That Wikipedia article links to the following Stack Overflow post, which covers a similar question: Authoritative position of duplicate HTTP GET query keys

The issue here is that form parameters can be whatever you want them to be. Some web frameworks have settled on key[number]=value for arrays, others haven't. Interestingly, RFC1866 section 8.2.4, page 48 (note: this RFC is historical and not current) shows an example with the same key used twice in a form POST:

name=John+Doe
&gender=male
&family=5
&city=kent
&city=miami
&other=abc%0D%0Adef
&nickname=J%26D

On the W3C side of things, HTML 4.01 has some information about how to encode form parameters. Sadly this doesn't cover arrays.

At the time of writing, I don't think there is a correct answer to your question - no IETF RFC or W3C spec defines the behavior that you're interested in.

(As a side note, the W3C HTML JSON form submission draft spec covers posting arrays, thank goodness.)

Community
  • 1
  • 1
Brian Beckett
  • 4,742
  • 6
  • 33
  • 52
3

URIs are defined by RFC 3986.

However, what you're asking about is encoding of form parameters. You need to look up the HTML spec for that.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • I have read RFC3986, it makes no mention of arrays or brackets in URLs. – rook Apr 07 '13 at 13:26
  • Rook: yes. It's a question of form submission, not URI syntax. – Julian Reschke Apr 08 '13 at 11:39
  • No, it's not. I don't need an html form to send a request with query parameters. There is a mention of query params as the "searchpart" in https://www.ietf.org/rfc/rfc1738.txt but it doesn't go into any depth. – monty Oct 19 '22 at 22:19
  • @monty - neither HTTP nor the URI spec defone a format what goes into the query part. You can use what you want. If you want to interact with browser forms though, you need to do what the HTML spec says. – Julian Reschke Oct 21 '22 at 04:49