none
REST URL Encoding? RRS feed

  • Question

  • I'm setting up a web service with an extremely simple API:

    [Route("api/ErrorLog/Add/{description}")]

    Despite numerous articles and posts on this question, I still have not found the answer to this question:  which encoder should I be using for a string?  I want to be able to support all special characters, including CRLF.  I've tried the following, and none work:

    • HttpUtility.UrlEncode
    • HttpUtility.HtmlEncode
    • HttpUtility.HtmlAttributeEncode
    • HttpUtility.JavaScriptStringEncode
    • HttpUtility.UrlPathEncode
    • WebUtility.UrlEncode
    • WebUtility.HtmlEncode
    • Uri.EscapeDataString

    Don't get sidetracked: I'm only trying to encode the description.  That line looks like this:

    string requestUri = $"api/ErrorLog/Add/{theencoder(description)}";

    If REST really is all the rage, this should be TRIVIAL.

    Any help would be much appreciated!  Thanks in advance.

    Brad.

    Friday, June 15, 2018 9:51 PM

All replies

  • Hi Brad,

    If the proivded function did not meet your requirement, I would suggest you try custom it by yourself.

    If it's a URL you can use the percent-encoded value for a new line,

    it's %0D%0A although %0A (ASCII 10 - line feed) or %0D (ASCII 13 - carriage return)

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 18, 2018 5:35 AM
  • I'm sorry but that's a terrible answer.  There's no way this is unique enough to warrant my own custom function!
    Monday, June 18, 2018 4:05 PM
  • Hi Pletazky,

    Do you get any issue while implementing your own function to encode CRLF?

    There is no built-in library to achieve your requirement.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 19, 2018 3:10 AM