Multiple Http Get Parameters with the Same Identifier

Correct way to pass multiple values for same parameter name in GET request

Indeed, there is no defined standard. To support that information, have a look at wikipedia, in the Query String chapter. There is the following comment:

While there is no definitive standard, most web frameworks allow
multiple values to be associated with a single field.[3][4]

Furthermore, when you take a look at the RFC 3986, in section 3.4 Query, there is no definition for parameters with multiple values.

Most applications use the first option you have shown: http://server/action?id=a&id=b. To support that information, take a look at this Stackoverflow link, and this MSDN link regarding ASP.NET applications, which use the same standard for parameters with multiple values.

However, since you are developing the APIs, I suggest you to do what is the easiest for you, since the caller of the API will not have much trouble creating the query string.

Multiple HTTP GET parameters with the same identifier

According to this comment from the PHP manual, PHP's query string parser will drop duplicate params... so I don't think that PHP is a good fit for what you want to do (except in that it has the same capacity as javascript to get the raw query string, with which you can do whatever you want)

Sending HTTP request with multiple parameters having same name

Although POST may be having multiple values for the same key, I'd be cautious using it, since some servers can't even properly handle that, which is probably why this isn't supported ... if you convert "duplicate" parameters to a list, the whole thing might start to choke, if a parameter comes in only once, and suddendly you wind up having a string or something ... but i guess you know what you're doing ...

I am sorry to say so, but what you want to do, is not possible in pure AS2 ... the only 2 classes available for HTTP are LoadVars and XML ... technically there's also loadVariables, but it will simply copy properties from the passed object into the request, which doesn't change your problem, since properties are unique ...

if you want to stick to AS2, you need an intermediary tier:

  1. a server to forward your calls. if you have access to the server, then you create a new endpoint for AS2 clients, which will decode the requests and pass them to the normal endpoint.
  2. use javascript. with flash.external::ExternalInterface you can call JavaScript code. You need to define a callback for when the operation is done, as well as a JavaScript function that you can call (there are other ways but this should suffice). Build the request string inside flash, pump it to JavaScript and let JavaScript send it to the server in a POST request and get the response back to flash through the callback.

up to you to decide which one is more work ...

side note: in AS3, you'd use flash.net::URLLoader with dataFormat set to flash.net::URLLoaderDataFormat.TEXT, and then again encode parameters to a string, and send them.

Add multiple parameters with same name in Angular 11

Reason is set and append returns a new instance so make sure you keep it updated. Based on doc.

let params = new HttpParams().append('value', '1');
params = params.append('value', '2');
params = params.append('value', '3');
params = params.append('value', '4');

console.log(params.getAll('value'));

So you should write something like this:

private getParams(value: string): HttpParams {
const values:string[] = value.split("/");

let httpParams:HttpParams = new HttpParams();

values.forEach((item) => {
httpParams = httpParams.append('value', item)
});

return httpParams;
}

How to get multiple parameters with same name from a URL in PHP

Something like:

$query  = explode('&', $_SERVER['QUERY_STRING']);
$params = array();

foreach( $query as $param )
{
// prevent notice on explode() if $param has no '='
if (strpos($param, '=') === false) $param += '=';

list($name, $value) = explode('=', $param, 2);
$params[urldecode($name)][] = urldecode($value);
}

gives you:

array(
'ctx_ver' => array('Z39.88-2004'),
'rft_id' => array('info:oclcnum/1903126', 'http://www.biodiversitylibrary.org/bibliography/4323'),
'rft_val_fmt' => array('info:ofi/fmt:kev:mtx:book'),
'rft.genre' => array('book'),
'rft.btitle' => array('At last: a Christmas in the West Indies.'),
'rft.place' => array('London'),
'rft.pub' => array('Macmillan and co.'),
'rft.aufirst' => array('Charles'),
'rft.aulast' => array('Kingsley'),
'rft.au' => array('Kingsley, Charles'),
'rft.pages' => array('1-352'),
'rft.tpages' => array('352'),
'rft.date' => array('1871')
)

Since it's always possible that one URL parameter is repeated, it's better to always have arrays, instead of only for those parameters where you anticipate them.

Multiple parameters by the same name

Web API parameter binding is not able to convert several parameters from the query string into an array, so you have to two options:

  • customize the parameter binding
  • manually access and convert the query string parameters

The second option includes getting the query string name-value pairs, and parsing them yourself. To get the name value pairs, use this:

Request.GetQueryNameValuePairs()

To extract the int values, you can do something like this:

var values= Request.GetQueryNameValuePairs()
.Where(kvp => kvp.Key == "someVal")
.Select(kvp => int.Parse(kvp.Value))
.ToArray();

Of course, you should control errors on the parsing and so on. This is a basic sample code.

This is an implementation of a model binder for the first option:

public class IntsModelBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof (Ints))
{
return false;
}
var intValues = actionContext.Request.GetQueryNameValuePairs()
.Where(kvp => kvp.Key == bindingContext.ModelName)
.Select(kvp => int.Parse(kvp.Value))
.ToList();
bindingContext.Model = new Ints {Values = intValues};
return true;
}
}

Again, this is a basic implementation that, between other things, lacks the control of errors.

This is one of the ways to use it in an action, but, please, read the link on parameter binding to see other (better) ways of using it:

// GET api/Test?keys=1&keys=7
public string Get([ModelBinder(typeof(IntsModelBinder))]Ints keys)
{
return string.Format("Keys: {0}", string.Join(", ", keys.Values));
}

Effectively way of handling multiple parameters as input in GET Request

You can take a look at this post: Correct way to pass multiple values for same parameter name in GET request

There's no standard for what you are asking for, but you can take an argument as comma-separated values and split them in Java, or something like that. For example:

my.api.com/search?color=black,red,yellow,orange

or

my.api.com/search?color=black&color=red&color=yellow&color=orange

There also is a comment I really like, that says that the first approach (csv) should be used as OR (I want to search either black, either red, either yellow, either orange objects), and the second approach should be used as an AND (I want an object which is black, red, yellow AND orange, all of them). That comment is the following one: "A would suggest using id=a&id=b as boolean AND, and id=a,b as boolean OR. – Alex Skrypnyk May 7 '16 at 5:13" (on the checked answer).

How to capture multiple GET parameters with the same identifier in Google Apps Script

Figured this out.

In your doGet or doPost function, instead of calling e.parameter you need to call e.parameters to get multiple parameters with the same name as arrays.

Documentation:
https://developers.google.com/apps-script/guides/web?hl=en#url_parameters



Related Topics



Leave a reply



Submit