Call Baidu Translator API interface function

Source: Internet
Author: User

    Public stringAppID ="their own appid.";  Public stringQ ="the text to translate";  Public stringSalt ="1435660288";  Public stringKey ="your secret key.";  Public string  from="your source language, such as zh";  Public stringto ="languages to be translated such as En";  Public stringGetjson () {varClient =NewRestclient ("http://api.fanyi.baidu.com"); varRequest =NewRestrequest ("/api/trans/vip/translate", Method.get); Request. Addparameter ("Q", q); Request. Addparameter (" from", from); Request. Addparameter (" to", to); Request. Addparameter ("AppID", AppID); Request. Addparameter ("Salt", salt); Request. Addparameter (" Sign", GetMd5 ()); Irestresponse Response=client.            Execute (Request); returnResponse.        Content; }         Public stringSign {Get{return string. Format ("{0}{1}{2}{3}", AppID, Q, salt, key); }        }        stringGetMd5 () {varMD5 =NewMD5CryptoServiceProvider (); varresult =Encoding.UTF8.GetBytes (sign); varOutput =Md5.computehash (Result); returnBitconverter.tostring (Output). Replace ("-","").        ToLower (); }        Private voidButton1_Click (Objectsender, EventArgs e) {TextBox2.Text=GetResult (); }         Public stringGetResult () {varLST =Newlist<string>(); varContent =Getjson (); DynamicJSON =jsonconvert.deserializeobject (content); foreach(varIteminchJson.trans_result) {lst.            ADD (Item.dst.ToString ()); }            return string. Join (";", LST); }

To reference Newtonsoft.Json.dll

Https://download.csdn.net/download/jsqdragoon/10032906?web=web

Call Baidu Translator API interface function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.