I need to make a query with a string, variable long and can have several simultaneous queries: String:
http://localhost:39051/api/values/punto1?name=125.25
http://localhost:39051/api/values/punto1?name=125.25&name1=1&name2=23.98
http://localhost:39051/api/values/punto1?name=125.25&name1=1&name2=23.98&name3=12.5
http://localhost:39051/api/values/punto1?name=125.25&name1=1&name2=23.98&name3=12.5&name6=34&name23=3
I have this configuration in webApiConfig.cs
config.Routes.MapHttpRoute(
name: "name",
routeTemplate: "api/{controller}/{id}/{name}/{name1}/{name2}",
defaults: new { id = RouteParameter.Optional, action = "GetProductsByName", name = string.Empty, name1 = string.Empty, name2 = string.Empty });
And I call GetProductsByName (....), which is in ValuesController.cs, where is the GET, POST, etc.
public string GetProductsByName (string name, string name1, string name2)
{
return "Requested name:" + ":" + name + ":" + name1 + ":" + name2;
}
It works and brings me the parameters name, name1 name2 and. But if I want to see more parameters, I have to define the in config.Routes. Which makes the system more complicated.
Need to separate the data into two parts and put them in string variables. For example:
http://localhost:39051/api/values/punto1?name=125.25&name1=1&name2=23.98
string1: punto1
and the other string is put everything after the?
string2: name=125.25&name1=1&name2=23.98
or
string2: name=125.25&name1=1&name2=23.98&name3=12.5&name6=34&name23=3
Depending on the case
Then string2 separate process to scan values.
It works perfectly, I tried it and brings the data correctly.
One more query, if I get 4 different parameters, in consultation, as would be the separation of parameters for example:
http://localhost:39051/api/values/punto1.25?name=5.25&name1=1&valor1=23.98&valor2=0.125&book2=17&book1=8&nivel15=9&nivel20=8