What's the difference between EscapeUriString and EscapeDataString?

前端 未结 5 1299
旧时难觅i
旧时难觅i 2020-11-27 11:34

If only deal with url encoding, I should use EscapeUriString?

5条回答
  •  误落风尘
    2020-11-27 11:43

    A simple example

    var data = "example.com/abc?DEF=あいう\x20えお";
    
    Console.WriteLine(Uri.EscapeUriString(data));
    Console.WriteLine(Uri.EscapeDataString(data));
    Console.WriteLine(System.Net.WebUtility.UrlEncode(data));
    Console.WriteLine(System.Web.HttpUtility.UrlEncode(data));
    
    /*
    =>
    example.com/abc?DEF=%E3%81%82%E3%81%84%E3%81%86%20%E3%81%88%E3%81%8A
    example.com%2Fabc%3FDEF%3D%E3%81%82%E3%81%84%E3%81%86%20%E3%81%88%E3%81%8A
    example.com%2Fabc%3FDEF%3D%E3%81%82%E3%81%84%E3%81%86+%E3%81%88%E3%81%8A
    example.com%2fabc%3fDEF%3d%e3%81%82%e3%81%84%e3%81%86+%e3%81%88%e3%81%8a
    */
    

提交回复
热议问题