Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can one avoid illegal characters when composing a URL?
    text
    copied!<p>I'm writing a web application that <em>dynamically</em> creates URL's based off of some input, to be consumed by a client at another time. For discussion sake these URL's can contain certain characters, like a <strong>forward slash (i.e. '/')</strong>, which should not be interpreted as part of the actual URL, but just as an argument. For example:</p> <pre>http://mycompany.com/PartOfUrl1/PartOfUrl2/ArgumentTo/Url/GoesHere</pre> <p>As you can see, the <strong>ArgumentTo/Url/GoesHere</strong> does indeed have forward slashes but these should be <em>ignored or escaped</em>. </p> <p>This may be a bad example but the question in hand is more general and applies to other <em>special characters</em>. </p> <h3>So, if there are pieces of a URL that are just <em>argument</em>s and should not be used to resolve the actual web request, what's a good way of handling this?</h3> <h1>Update:</h1> <p>Given some of the answers I realized that I failed to point out a few pieces that hopefully will help clarify. </p> <p>I would like to keep this fairly language agnostic as it would be great if the client could just make a request. For example, if the client knew that it wanted to pass <strong>ArgumentTo/Url/GoesHere</strong>, it would be great if that could be <em>encoded</em> into a <em>unique</em> string in which the server could turn around and <em>decode</em> it to use. </p> <p>Can we assume that similar functions like HttpUtility.HtmlEncode/HtmlDecode in the .NET Framework are available on other systems/platforms? The URL does not have to be <em>pretty</em> by any means so having <em>real words</em> in the path does not really matter.</p> <h3>Would something like a base64 encoding of the argument work?</h3> <p>It seems that base64 encoding/decoding is fairly readily available on any platform/language. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload