I’m tryinig to load a file from a web server with a request URL that contains a parameter with cyrillic chars.
But I’m not getting this to work in c#, even if I URL-Encode the param.
When I open the page in IE with
http://translate.google.com/translate_tts?tl=ru&q=ЗДРАВСТВУЙТЕ
the server does not respond.
Using the URL-encoded version
http://translate.google.com/translate_tts?tl=ru&q=%d0%97%d0%94%d0%a0%d0%90%d0%92%d0%a1%d0%a2%d0%92%d0%a3%d0%99%d0%a2%d0%95
the server responds as expected.
Now my problem:
I want to download the MP3 from C# …
var url = string.Format("http://translate.google.com/translate_tts?tl=ru&q={0}",
Server.UrlEncode("ЗДРАВСТВУЙТЕ"));
System.Net.WebClient client = new WebClient();
var res = client.DownloadData(url);
And this does NOT work with cyrillic chars. I always get a zero-byte answer, like the first, non-encoded request.
When I send “normal” chars, the code above works fine.
So … I’m doing something wrong.
Any hints? Tipps? Solutions?
Thanks
Michael
You have to set the user-agent for the
WebClient– this works:From the msdn documentation: