Url encoding quotes and spaces

后端 未结 3 656
太阳男子
太阳男子 2020-12-23 21:11

I have some query text that is being encoded with JavaScript, but I\'ve encountered a use case where I might have to encode the same text on the server side, and the encodin

相关标签:
3条回答
  • 2020-12-23 21:50

    UrlPathEncode doesn't escape " because they don't need to be escaped in path components.

    Uri.EscapeDataString should do what you want.

    0 讨论(0)
  • 2020-12-23 21:58
    WebUtility.UrlEncode(str)
    

    Will encode all characters that need encoded using the %XX format, including space.

    0 讨论(0)
  • 2020-12-23 21:59

    There are a few options available to you, the fastest might be to use UrlEncode then do a string.replace to swap the + characters with %20.

    Something like

    HttpUtility.UrlEncode(input).Replace("+", "%20");
    
    0 讨论(0)
提交回复
热议问题