question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple fields with the same parameter in a POST.

See original GitHub issue

I am interacting with an API that allows for multiple fields of the same name to be included in a post request. The app is still under development and not available publicly.

HttpResponse<JsonNode> jsonResponse = Unirest.post(url)
                    .header("Authorization", "Token " + apikey)
                    .field("parameter", "value1")
                    .field("parameter", "value2")
                    .asJson();

The problem I am having is that when I have two fields with the same name, unirest only takes the second one and neglects the first one.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
orliesauruscommented, Jul 2, 2014

@varunkm I am not sure it is REST compliant to have multiple fields with the same name but holding different values, basically you need to rethink the API design you have got and use an array to store the values of that particular field. Someone correct me if I am wrong to assume that 💃 thanks! The above basically tells why #42 is not an issue to me (at least)

0reactions
sarguecommented, Aug 9, 2018

Sorry to reopen this old bug but I’ve stumbled upon it right now trying to use this library to access the Mailgun API service.

I disagree on this:

I am not sure it is REST compliant to have multiple fields with the same name but holding different values, basically you need to rethink the API design

REST is strongly based on HTTP and multiple fields with the same value is a common scenario with HTTP. Be it query strings or form data (body of a POST). The latter is the scenario of the OP.

As an example of an API that requires this usage is the same Mailgun service. To send a mail with multiple attachments you need this funcionality as you can’t send them as query parameters.

I’ve tested this with the Jersey 2 client library and it works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to pass multiple values for same parameter name ...
Most applications use the first option you have shown: http://server/action?id=a&id=b .
Read more >
Search Multiple Fields Same Parameter
You have two different options. You can either use Crafts search so your string would be listingAgent:*searchterm* OR ...
Read more >
REST Post multiple parameters with same name
Hi all, I'm trying to send a REST POST request with a multipart/form-data content. In particular, I need to send the same parameter...
Read more >
How to Create Multiple Select Parameters in Tableau | phData
This post will differ as it offers a simplistic approach to developing multiple select parameters and more-or-less uses the same base ...
Read more >
Request Parameters in Postman - Javatpoint
Enter the same URL in the Postman text field; you will get the multiple parameters in the Params tab. Even you can write...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found