• 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;
                }
            }
        }
  • 相关阅读:
    Nginx 之负载均衡与反向代理
    PHP 之快递100接口封装
    Mongodb非关系型数据库
    Sphinx全文索引引擎
    PHP 之文件上传类封装
    PHP 之验证码类封装
    小程序 之左滑删除
    PHP 之实现按日期进行分组、分页
    System.IO 二
    IIS配置MIME类型
  • 原文地址:https://www.cnblogs.com/hun_dan/p/2225574.html
Copyright © 2020-2023  润新知