获取url参数



private
static string GetQueryParam(string url,string name) { if (string.IsNullOrWhiteSpace(url)) { return string.Empty; } if(!Regex.IsMatch(url, "(http[s]?:\\/\\/)?([^\\/\\s]+\\/)(.*)",RegexOptions.IgnoreCase)) { return string.Empty; } if (string.IsNullOrWhiteSpace(name)) { return string.Empty; } var query = new Uri(url).Query.TrimStart('?'); if (string.IsNullOrWhiteSpace(query)) { return string.Empty; } Dictionary<string, string> dicQueryString = query.Split('&') .ToDictionary(c => c.Split('=')[0].ToLower(), c => Uri.UnescapeDataString(c.Split('=')[1])); if (!dicQueryString.Keys.Contains(name)) { return string.Empty; } return dicQueryString[name.ToLower()]; }

 

posted on 2017-12-22 19:57  b4b4  阅读(170)  评论(0编辑  收藏  举报

导航