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

posted on 2024-10-20 12:10  空明流光  阅读(7)  评论(0编辑  收藏  举报

导航