I have a URL: http://localhost:8080/search.json?q=L%u00e6rwhich is an encoded search for Lær.
Unfortunately, creating WebRequest from this URL using the WebRequest.Create(url)leads to the following URL: http://localhost:8080/search.json?q=L%25u00e6r.
Please note that it decodes %u00e6and produces incorrectly %25u00e6r. Is there a way to convert this unicode type of a shielded value or get WebRequest.Create to handle it correctly?
This will most likely be reported as an error for the .net command. WebRequest.Create()cannot use the query string returned Request.QueryString.ToString()if the query contains §, æ, ø, or å (or any other non-ascii character). Here is a small mvc action that you can use to verify it. Call him with a requestQuery?q=L%C3A6r
public ActionResult Query()
{
var query = Request.QueryString.ToString();
var url = "http://localhost:8080?" + query;
var request = WebRequest.Create(url);
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
return new FileStreamResult(stream, "text/plain");
}
}
Edit
Unfortunately, @animaonline's solution doesn’t work with URLs such as http://localhost:8080/search.json?q=Lek+%26+L%u00e6rthat are decoded in http://localhost:8080/search.json?q=Lek & Lær, where it WebRequest.Creategets confused in &and considers that it shares the parameters, and is not part of the parameter q.
source
share