zoukankan      html  css  js  c++  java
  • Bing翻译实例

     public static String Translate(String strTranslateString, string flang, string tlang)
        {
            string appId = "AFC76A66CF4F434ED080D245C30CF1E71C22959C"//http://www.bing.com/toolbox/bingdeveloper/ 申请自己的appid
            string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + appId + "&text=" + System.Web.HttpUtility.UrlEncode(strTranslateString) + "&from=" + flang + "&to=" + tlang + "";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
            WebResponse response = null;
            try
            {
                response = httpWebRequest.GetResponse();
                using (Stream stream = response.GetResponseStream())
                {
                    System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
                    return (string)dcs.ReadObject(stream);
                }
            }
            catch (WebException)
            {
                return "翻译失败";
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                    response = null;
                }
            }
        }
  • 相关阅读:
    问题解决-Plugin with id 'com.github.dcendents.android-maven' not found
    hadoop 04 一 HA高可用配置
    hadoop 03 一 Hadoop机架感知配置
    Windows平台安装配置Hadoop
    hadoop 02一 hadoop配置
    hadoop 01一 hadoop安装配置
    Centos7下载和安装教程
    mysql 命令行导出数据
    RabbitMQ 集群部署(linux-centos6.5)
    Spring 集成RabbitMq
  • 原文地址:https://www.cnblogs.com/hun_dan/p/2225574.html
Copyright © 2011-2022 走看看