获得从乌里单独的查询参数参数

2023-09-02 21:30:02 作者:乱一世狂傲

我有一个URI字符串,如:http://example.com/file?a=1&b=2&c=string%20param

I have a uri string like: http://example.com/file?a=1&b=2&c=string%20param

有一个现有的函数,将转换查询参数字符串转换成一本字典一样的方式ASP.NET Context.Request做的。

Is there an existing function that would convert query parameter string into a dictionary same way as ASP.NET Context.Request does it.

我正在写一个控制台应用程序,而不是一个Web服务,所以没有Context.Request解析URL我。

I'm writing a console app and not a web-service so there is no Context.Request to parse the URL for me.

我知道这是pretty的易开裂查询字符串自己,但我宁愿使用FCL功能是否存在。

I know that it's pretty easy to crack the query string myself but I'd rather use a FCL function is if exists.

推荐答案

您可以使用:

var queryString = url.Substring(url.IndexOf('?')).Split('#')[0]
System.Web.HttpUtility.ParseQueryString(queryString)

MSDN