开发者

Wrong encoding when getting response from Google's translate API?

开发者 https://www.devze.com 2023-01-28 00:24 出处:网络
I am using google translate API to translate text from English to German. The code i am using is: string url = String.Format(\"http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&lan

I am using google translate API to translate text from English to German. The code i am using is:

string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", TxtEnglish.Text, Constants.LanguagePair);

WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;

webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(TextTranslation_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(url));

On开发者_运维技巧 receiving the response in e.Result....... Original text: Can you help me?

Translated german text on translator page: können Sie mir helfen

Result in e.Result: k�nnen Sie mir helfen

So, plz help me know why this "�" special character is coming and how can i fix this issue??


Use Fiddler to check the response headers and you will find the encoding in there.

The way it is being shown could be unrelated to the data you receive and could be related to the way you are representing it in your UI code. Share that and we will have a look.

0

精彩评论

暂无评论...
验证码 换一张
取 消