通过动态参数[重复]将动态参数通过其余URL传递给C#方法

问题描述 投票:0回答:2

这个问题在这里已有答案:

我想通过动态参数将动态参数通过rest URL传递给C#方法。例如,我想调用这样的休息URL:

http://localhost:2000/custom?**user=admin?password=admin?brand=dell&limit=20&price=20000&type1=laptop&type2=phone**

对于一个动态参数的C#方法,动态参数取“user”及其值“admin”,“brand”及其值“dell”等,并处理它们。

请有人帮帮我。

c# asp.net post asp.net-web-api keyvaluepair
2个回答
1
投票

如果要将Web API与动态参数一起使用,则需要将其用作POST方法。

网址:http://localhost:2000/custom

数据:

{
user:"admin"
password:"admin",
brand:"dell",
limit:20
}

0
投票

你可以使用NameValueCollection返回的ParseQueryString

Uri myUri = new Uri("http://localhost:2000/custom?user=admin?password=admin?brand=dell&limit=20&price=20000&type1=laptop&type2=phone");
string user= HttpUtility.ParseQueryString(myUri.Query).Get("user");
string password= HttpUtility.ParseQueryString(myUri.Query).Get("password");
string brand= HttpUtility.ParseQueryString(myUri.Query).Get("brand");
string limit= HttpUtility.ParseQueryString(myUri.Query).Get("limit");
...

但是传递用户:传递GET和明文是如此糟糕(非常糟糕)的想法:)

© www.soinside.com 2019 - 2024. All rights reserved.