Created
January 25, 2019 02:51
-
-
Save isdaviddong/9324aa87aa99b230af038efeaa518da0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static List<MSTranslatorTextTranslateResult> Translate(string text, string LanguageCode) | |
| { | |
| // Translate to German and Italian. | |
| string path = "/translate?api-version=3.0"; //翻譯 | |
| string params_ = "&to=" + LanguageCode; //目標語系 | |
| string uri = MSTranslatorTextHost + path + params_; | |
| System.Object[] body = new System.Object[] { new { Text = text } }; | |
| var requestBody = JsonConvert.SerializeObject(body); | |
| using (var client = new HttpClient()) | |
| using (var request = new HttpRequestMessage()) | |
| { | |
| request.Method = HttpMethod.Post; | |
| request.RequestUri = new Uri(uri); | |
| request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json"); | |
| request.Headers.Add("Ocp-Apim-Subscription-Key", MSTranslatorTextKey); | |
| var response = client.SendAsync(request).Result; | |
| var responseBody = response.Content.ReadAsStringAsync().Result; | |
| var result = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MSTranslatorTextTranslateResult>>(responseBody); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment