NameValueCollection to URL Query?

前端 未结 12 2050
温柔的废话
温柔的废话 2020-11-28 05:36

I know i can do this

var nv = HttpUtility.ParseQueryString(req.RawUrl);

But is there a way to convert this back to a url?

v         


        
12条回答
  •  难免孤独
    2020-11-28 06:28

    Actually, you should encode the key too, not just value.

    string q = String.Join("&",
    nvc.AllKeys.Select(a => $"{HttpUtility.UrlEncode(a)}={HttpUtility.UrlEncode(nvc[a])}"));
    

提交回复
热议问题