日期:2014-05-17 浏览次数:20921 次
/// <summary>
/// 翻译方法
/// </summary>
/// <param name="textstr">需要翻译的内容</param>
/// <param name="language">被翻译的语言</param>
/// <param name="tolanguage">翻译成的语言</param>
/// <returns></returns>
public static string GetGoogtextStr(string textstr, string language, string tolanguage)
{
WebClient web = new WebClient();
WebHeaderCollection headers = new WebHeaderCollection();
headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded; charset=utf-8";
headers[HttpRequestHeader.Referer] = "http://translate.google.cn/";
web.Headers = headers;
string text = textstr;
string url = string.Format("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q={0}&langpair={1}%7C{2}", text, language, tolanguage);
byte[] bystr = web.DownloadData(url);
string urldata = GetText(System.Web.HttpUtility.UrlDecode(bystr, Encoding.UTF8)); //GetText在哪呢?
return urldata;
}