network to get json

Signed-off-by: lilium-saber <WR364999428@hotmail.com>
GDN
lilium-saber 1 year ago
parent 230a999be4
commit 44887c1dd4

@ -20,14 +20,10 @@ namespace WpfApp1.translationKey
{
static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?";
static string trans = "tradition";
static string appid = "20230925001829663";//20230925001829663,20230923001827495
static string fl = "en";
static string dl = "zh";
static Random rd = new Random();
static string salt = rd.Next(100000).ToString();
static string key = "f7ZHpw28izQ1VU_ixoY5";//f7ZHpw28izQ1VU_ixoY5,yjvMNY33Qc1TYSBjTQYQ
static string sign = EncryptString(appid + trans + salt + key);
//static HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple&from=en&to=zh&appid=20230925001829663&salt=1435660288&sign=c963bc2275c0fd1ed30da014c1ef1933");
@ -68,13 +64,36 @@ namespace WpfApp1.translationKey
return sb.ToString();
}
public void requestJson()
public string RequestJsonLanguageChange(string input, string srcl, string dstl)
{
string sign = EncryptString(appid + input + salt + key);
string temp = "q=" + HttpUtility.UrlEncode(input) + "&from=" + srcl + "&to=" + dstl + "&appid=" + appid + "&salt=" + salt + "&sign=" + sign;
Console.WriteLine(https + temp);
//Task t = GetAsync(HttpRe); t.Wait();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(https + temp);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
request.UserAgent = null;
request.Timeout = 6000;
var response = request.GetResponse();
var myResponseStream = response.GetResponseStream();
var myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
tempC2 temp1 = JsonConvert.DeserializeObject<tempC2>(retString);
Trans_result result = temp1.trans_result[0];
string s = result.dst;
return s;
}
public string RequestJsonBaiDu(string input)
{
string sign = EncryptString(appid + input + salt + key);
string temp = "q=" + HttpUtility.UrlEncode(trans) + "&from=" + fl + "&to=" + dl + "&appid=" + appid + "&salt=" + salt + "&sign=" + sign;
string temp = "q=" + HttpUtility.UrlEncode(input) + "&from=jp&to=zh&appid=" + appid + "&salt=" + salt + "&sign=" + sign;
Console.WriteLine(https + temp);
//Task t = GetAsync(HttpRe); t.Wait();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(https + temp);
@ -89,9 +108,10 @@ namespace WpfApp1.translationKey
var myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
tempC2 temp1 = JsonConvert.DeserializeObject<tempC2>(retString);
Trans_result result = temp1.trans_result[0];
string s = result.dst;
Console.WriteLine(s);
return s;
}

Loading…
Cancel
Save