Skip to content

Commit

Permalink
SendAsync -> PostAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
imba-tjd committed Jul 14, 2020
1 parent c5d9001 commit 2b72495
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions TranslatorLibrary/CaiyunTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -60,7 +59,7 @@ public string Translate(string sourceText, string desLang, string srcLang)
}
finally
{
request.Dispose();
req.Dispose();
}

CaiyunTransResult oinfo;
Expand Down

0 comments on commit 2b72495

Please sign in to comment.