我想将字符串从一种语言翻译成另一种语言。我试过这段代码:
input = clipoard_word;
string languagePair = "en|bn";
string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;
try
{
result = webClient.DownloadString(url);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
result = result.Substring(result.IndexOf("<span title=\"") + "<span title=\"".Length);
result = result.Substring(result.IndexOf(">") + 1);
result = result.Substring(0, result.IndexOf("</span>"));
result = WebUtility.HtmlDecode(result.Trim());
label1.Text = result;
但是我遇到了一个例外:
result = webClient.DownloadString(url);
错误消息说:
底层连接已关闭;接收时发生意外错误
这里有什么问题,我该如何解决?N:B:我不想在这里使用谷歌翻译 api。