最近自己写翻译api,网上找到3个接口:http://dev.son1c.com/show/1248.html
使用第二种,爱词霸api接口,老是不成功。有成功的大神赐教下。
winform应用程序:
/// <summary>
/// 调用爱词霸翻译
/// </summary>
/// <param name=”soutext”>翻译原文</param>
/// <returns>返回译文</returns>
private static string StartTranslation(string soutext, string Id, string KeyFrom)
{
if (string.IsNullOrEmpty(soutext))
return “”;
try
{
HttpWebRequest hwr = WebRequest.Create(string.Format(“http://dict-co.iciba.com/api/dictionary.php?w=#{word}+ System.Web.HttpUtility.UrlEncode(soutext)) as HttpWebRequest;
hwr.Method = “GET”;
XmlDocument doc = new XmlDocument();
doc.Load(hwr.GetResponse().GetResponseStream());
XmlNode node = doc.SelectSingleNode(“//paragraph”);
if (node != null)
{
return node.InnerText;
}
else
{
return “”;
}
}
catch (Exception ex)
{
return “”;
}
}
使用第二种,爱词霸api接口,老是不成功。有成功的大神赐教下。
winform应用程序:
/// <summary>
/// 调用爱词霸翻译
/// </summary>
/// <param name=”soutext”>翻译原文</param>
/// <returns>返回译文</returns>
private static string StartTranslation(string soutext, string Id, string KeyFrom)
{
if (string.IsNullOrEmpty(soutext))
return “”;
try
{
HttpWebRequest hwr = WebRequest.Create(string.Format(“http://dict-co.iciba.com/api/dictionary.php?w=#{word}+ System.Web.HttpUtility.UrlEncode(soutext)) as HttpWebRequest;
hwr.Method = “GET”;
XmlDocument doc = new XmlDocument();
doc.Load(hwr.GetResponse().GetResponseStream());
XmlNode node = doc.SelectSingleNode(“//paragraph”);
if (node != null)
{
return node.InnerText;
}
else
{
return “”;
}
}
catch (Exception ex)
{
return “”;
}
}