Skip to content

Disable automatically added square brackets at end of array name #46

Description

@adm7373

Say I want to post an array of data to a remote source:

    array = [1,2,3]
    Unirest.post "https://www.my-website.com", parameters: { data: array }

When I receive the HTTP request on my-website.com, the body of the POST looks like this: data[]=1&data[]=2&data[]=3

According to this StackOverflow post, those square brackets are a convention to "address a limitation of PHP, which doesn't generate an array automatically if multiple values with the same name are submitted". All well and good if I'm posting to a PHP server, but if I'm posting to a different kind of server (in my case NancyFx), I can't easily get that data into an array.

I think it would make sense to get rid of these brackets by default and allow developers using unirest-ruby to post to a PHP server to do something like this:

    array = [1,2,3]
    Unirest.post "https://www.my-website.com", parameters: { "data[]": array }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions