Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble encoding a u umlaut with in a .Net http handler
    primarykey
    data
    text
    <p>I have a JavaScript request going to a ASP.Net (2.0) HTTP handler which passes the request to a java web service. In this system special characters, such as those with an accent do not get passed on correctly.</p> <p>E.G.</p> <ul> <li>Human input: <code>Düsseldorf</code></li> <li>becomes a JavaScript asynch request to <code>http://site/serviceproxy.ashx?q=D%FCsseldorf</code>, which is valid in ISO-8859-1 as well as in UTF-8 as far as I can tell. (unless it's %c3%bc in UTF-8)</li> <li><code>HttpContext.Current.Request.QueryString.Get("q")</code> returns <code>D�sseldorf</code> which is where trouble begins.</li> <li>but <code>HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString.Get("q"), Encoding.GetEncoding("ISO-8859-1"))</code> returns <code>D%3fsseldorf</code> (a '?')</li> <li>and <code>HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString.Get("q"), Encoding.UTF8)</code> returns <code>D%ef%bfsseldorf</code></li> </ul> <p>So it the value doesn't get decoded nor re-encoded correctly to be passed on to the java service.</p> <ul> <li>Notice <code>HttpContext.Current.Request.Url.Query</code> is <code>?q=D%FCsseldorf&amp;output=json&amp;from=1&amp;to=10</code></li> <li>while <code>HttpContext.Current.Request.QueryString.ToString()</code> is <code>q=D%ufffdsseldorf&amp;output=json&amp;from=1&amp;to=10</code></li> </ul> <p>Why is this, and how can I tell the <code>HttpContext</code> to honor the request headers which include:</p> <pre><code>Content-Type=application/x-www-form-urlencoded;+charset=UTF-8 </code></pre> <p>and decode the URL's <code>QueryString</code> using the UTF-8 charset.</p> <p>Addendum: As the answer notes, the trouble lies not so much in the decoding as the encoding; using <code>escape()</code> in JavaScript does not escape according to UTF-8, while using <code>encodeURIComponent()</code> does.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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