1

I am trying to put a url, something like the following urn:test.project:123, as part of the url.

Does it make sense to encode urn:test.project:123 into urn%3atest.project%3a123 and decode it back to urn:test.project:123 at the receiver end?

http://{domain}/abc/urn%3atest.project%3a123/Manifest
Kalana
  • 5,631
  • 7
  • 30
  • 51
Eatdoku
  • 6,569
  • 13
  • 63
  • 98

2 Answers2

2

Yes, it's a valid character. It's the escape character for URLs in a similar way to how the ampersand & is the escape character for xml/html, and the backslash \ is the escape character for string literals in c-like languages. It's the (very important) character that allows you to specify (through an escape sequence) all the other characters that wouldn't be valid in a URL.

(And yes, it makes sense to encode such a string so it's a legal URL, and as @PaulPRO mentions, most frameworks will automatically decode it for you on the server-side.)

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
  • "http://localhost:4502/Person/urn%3atest.project%3a123/Manifest" im trying to hit this url, but iis return HTTP Error 404 - Bad Request. i am creating a REST api where the "rn%3atest.project%3a123" would be a urn – Eatdoku Jul 16 '11 at 16:13
  • @Eatdoku, a lot of frameworks will not allow URLs that have escape sequences in the path portion (as opposed to the query string portion) of the URL. What backend are you using as the server framework? – Kirk Woll Jul 16 '11 at 16:57
  • it's IIS 7.5, running .NET with OpenRasta/WCF – Eatdoku Jul 18 '11 at 16:42
  • @Eatdoku, take a look at this post: http://stackoverflow.com/questions/5682160/a-potentially-dangerous-request-path-value-was-detected-from-the-client. It discusses most of the same issues you're running into. The solution is more asp.net specific (I'm not sure if you're using OpenRasta on top of ASP.NET or not) but the general suggestion of not using special characters in the path, and instead converting them to "slugs" (undescores) probably makes sense for you too. – Kirk Woll Jul 18 '11 at 16:53
1

Yes, the %3a means that 3a is the HEX encoded value for ':' If you put it in the url as %3a your server will most likely automatically decode it.

Paul
  • 139,544
  • 27
  • 275
  • 264