From 2b724952664c242ce08e4ae1a3e0d733ff8596fa Mon Sep 17 00:00:00 2001 From: imba-tjd <109224573@qq.com> Date: Tue, 14 Jul 2020 18:17:30 +0800 Subject: [PATCH] SendAsync -> PostAsync --- TranslatorLibrary/CaiyunTranslator.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/TranslatorLibrary/CaiyunTranslator.cs b/TranslatorLibrary/CaiyunTranslator.cs index e648a6b1..8e516aff 100644 --- a/TranslatorLibrary/CaiyunTranslator.cs +++ b/TranslatorLibrary/CaiyunTranslator.cs @@ -45,13 +45,12 @@ public string Translate(string sourceText, string desLang, string srcLang) string jsonParam = "{\"source\": [\"" + q + "\"], \"trans_type\": \"" + trans_type + "\", \"request_id\": \"demo\", \"detect\": true}"; var hc = CommonFunction.GetHttpClient(); - var request = new HttpRequestMessage(HttpMethod.Post, url); - request.Headers.Add("X-Authorization", "token " + caiyunToken); - request.Headers.Add("ContentType", "application/json;charset=UTF-8"); - request.Content = new StringContent(jsonParam); + var req = new StringContent(jsonParam); + req.Headers.Add("X-Authorization", "token " + caiyunToken); + req.Headers.Add("ContentType", "application/json;charset=UTF-8"); try { - retString = hc.SendAsync(request).GetAwaiter().GetResult().Content.ReadAsStringAsync().GetAwaiter().GetResult(); + retString = hc.PostAsync(url, req).GetAwaiter().GetResult().Content.ReadAsStringAsync().GetAwaiter().GetResult(); } catch (WebException ex) { @@ -60,7 +59,7 @@ public string Translate(string sourceText, string desLang, string srcLang) } finally { - request.Dispose(); + req.Dispose(); } CaiyunTransResult oinfo;