c# 动态增删 url 中的 query string 查询参数
void Main() { var url = "http://www.demo.com/demo.html?a=1&b=2"; var uri = new Uri(url); var parameters = HttpUtility.ParseQueryString(uri.Query); parameters.Add("c","3"); parameters.Remove("b"); parameters["a"] = "0"; var builder = new UriBuilder(uri); builder.Query = parameters.ToString(); url = builder.ToString(); url.Dump(); }
运行结果:
http://www.demo.com:80/demo.html?a=0&c=3
桂棹兮兰桨,击空明兮溯流光。