title: What is the best way to design a HTTP request when somewhat complex parameters are needed?
body: <p>I have some web services that I am writing and I am trying to be as RESTful as possible.  I am hosting these web services using a HTTPHandler running inside of IIS/ASP.NET/SharePoint.</p>
  
  <p>Most of my services expect a HTTP GET.  I have two of these that are simply returning some data (i.e., a query) and will be <a href="http://en.wikipedia.org/wiki/Idempotent" rel="noreferrer">Idempotent</a>, but the parameters may be somewhat complex.  Both of them could include characters in the parameters of the service that are not allowed for at least the PATH portion of the URL.</p>
  
  <p>Using IIS, ASP.NET, and SharePoint I have found that the following characters in the URL path don't even make it to my HttpHandler even if Url encoded (the request blows up and I don't have any easy control over this):</p>
  
  <ul>
  <li>% (%25)</li>
  <li>&amp; (%26)</li>
  <li>* (%2a, but didn't Url encode)</li>
  <li>+ (%2b)</li>
  <li>: (%3a)</li>
  <li>&lt; (%3c)</li>
  <li><blockquote>
    <p>(%3e)</p>
  </blockquote></li>
  </ul>
  
  <p>The following characters made it to my HttpHandler, but the UriTemplate could not handle them properly even if Url encoded:</p>
  
  <ul>
  <li><h1>(%23)</h1></li>
  <li>. (%2e, but didn't Url encode; UriTemplate removed the "." if is is the last character before a /)</li>
  <li>? (%3f)</li>
  <li>/ (%2f - UriTemplate fails for obvious reasons even if UrlEncoded)</li>
  <li>\ (%5c)</li>
  </ul>
  
  <p>So, I've been somewhat thorough, but I need to test these url encoded characters in the query string.  It appears that this will work for the most part there.</p>
  
  <p>In one of my services, the special characters that are a parameter are semantically part of a query/filter (actually search terms for a search service), but in another they are not really part of a query/filter so ideally they are part of the path and not the query string.</p>
  
  <p>My question is, what option is best?  Here are some I know of:</p>
  
  <ol>
  <li><p><strong>Use HTTP GET and query string.</strong>  Anything that may use special characters should be on the query string and Url Encoded.  <em>This is where I am leaning, but I am concerned about extremely long query strings (IE has a 2083 limit)</em></p></li>
  <li><p><strong>Use HTTP GET and base64 encoding within path.</strong>  Use a <a href="http://en.wikipedia.org/wiki/Base64#URL_applications" rel="noreferrer">Modified Base64 for URL</a> for any parameters that might use special characters and keep them as part of the path if preferred.  <em>I have tried this and it works, but it is kind of ugly.  Still a concern about extremely long query strings.</em></p></li>
  <li><p><strong>Use HTTP POST and message body.</strong>  Anything that may use special characters should be in the body of the request.  <em>Seems like a decent solution, but posts are understood to <strong>not</strong> be <a href="http://en.wikipedia.org/wiki/Idempotent" rel="noreferrer">Idempotent</a> and (I thought) are generally meant for changes (whereas no change is occurring here).</em></p></li>
  <li><p><strong>Use HTTP GET and message body.</strong>  Anything that may use special characters should be in the body of the request.  This seems like a bad idea according to <a href="https://stackoverflow.com/questions/978061/http-get-with-request-body">SO: HTTP GET with request body</a> and <a href="http://tech.groups.yahoo.com/group/rest-discuss/message/9962" rel="noreferrer">Roy Fielding</a>.</p></li>
  <li><p>Use a combination of #3 and either #1 or #2 above depending on how large the request can be.</p></li>
  <li><p>Other???</p></li>
  </ol>
  
  <p>Note that in some cases I may be able to change things around to prevent special characters (and I may do that), but I won't be able to do this in all cases.</p>
  
  <hr>
  
  <p>Regarding URI length, <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1" rel="noreferrer">RFC2616 Sec3.2.1</a> says the following:</p>
  
  <p>The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).</p>
  
  <pre><code>  Note: Servers ought to be cautious about depending on URI lengths
    above 255 bytes, because some older client or proxy
    implementations might not properly support these lengths.
  </code></pre>
  
  <p>In addition the <a href="http://support.microsoft.com/kb/208427" rel="noreferrer">Maximum URL length is 2,083 characters in Internet Explorer</a>.</p>
  
  <blockquote>
    <p><strong>Related: <a href="https://stackoverflow.com/questions/872984/how-to-pass-complex-queries-in-rest">How to pass complex queries in REST?</a></strong></p>
  </blockquote>