system.net - How to prevent character unescaping with WebClient or HttpWebRequest or any .NET client? -


i making request http://translate.google.com/translate_tts?q=da%c3%b1o&tl=es-es audio recording. when use system.net.webclient, system.net.http.httpclient or webrequest.create, request sent http://translate.google.com/translate_tts?q=daño&tl=es-es instead. second url works, produces incorrect result.

how can send request %c3%b1 instead of ñ in path?

note cannot download these urls referral header (like, clicking them) if click them fail , result may cached copy'n'pasting url fails too. if want test urls, copy them clipboard, add q parameter avoid cached results.

adding repro tried using purify (same results without):

            var parameters = this.bind<speechrequest>();             parameters.q = "daño";             parameters.tl = "es-mx";              var url = string.format("http://translate.google.com/translate_tts?q={0}&tl={1}",                  webutility.urlencode(parameters.q), webutility.urlencode(parameters.tl));              var uri = new uri(url);             system.console.writeline("uri constructed string: " + url);             system.console.writeline("before purify: ");             showuridetails(uri);             uri.purify();             system.console.writeline("after purify:");             showuridetails(uri);              var request = system.net.webrequest.create(uri) httpwebrequest;  

output:

    uri constructed string: http://translate.google.com/translate_tts?q=da%c3%b1o&tl=es-mx     before purify:             uri.tostring() - http://translate.google.com/translate_tts?q=daño&tl=es-mx             uri.absoluteuri - http://translate.google.com/translate_tts?q=da%c3%b1o&tl=es-mx             uri.host - translate.google.com             uri.query - ?q=da%c3%b1o&tl=es-mx             uri.pathandquery - /translate_tts?q=da%c3%b1o&tl=es-mx             uri.absolutepath - /translate_tts             uri.fragment -     after purify:             uri.tostring() - http://translate.google.com/translate_tts?q=daño&tl=es-mx             uri.absoluteuri - http://translate.google.com/translate_tts?q=da%c3%b1o&tl=es-mx             uri.host - translate.google.com             uri.query - ?q=da%c3%b1o&tl=es-mx             uri.pathandquery - /translate_tts?q=da%c3%b1o&tl=es-mx             uri.absolutepath - /translate_tts             uri.fragment - 


Comments