Пример #1
0
        private static async Task <byte[]> GetDocumentFromStorage(AnalyzeFormData formData)
        {
            var uri = $"{formData.StorageUri}{formData.StorageSasToken}";

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Get;
                    request.RequestUri = new Uri(uri);

                    var response = await client.SendAsync(request).ConfigureAwait(false);

                    return(await response.Content.ReadAsByteArrayAsync());
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Use Cognitive Service to translate text from one language to another.
        /// </summary>
        /// <param name="originalText">The text to translate.</param>
        /// <param name="toLanguage">The language you want to translate to. Default is en (English).</param>
        /// <returns>Asynchronous task that returns the translated text. </returns>
        private static async Task <string> AnalyzeForm(AnalyzeFormData formData, string modelId, byte[] fileBytes)
        {
            var uri = $"{serviceEndpoint}/formrecognizer/v1.0-preview/custom/models/{modelId}/analyze";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);

                using (var request = new HttpRequestMessage())
                {
                    request.Method = HttpMethod.Post;
                    using (var requestContent = new ByteArrayContent(fileBytes))
                    {
                        requestContent.Headers.ContentType = new MediaTypeHeaderValue(formData.ContentType);
                        var response = await client.PostAsync(uri, requestContent);

                        var responseString = response.Content.ReadAsStringAsync();
                        return(await response.Content.ReadAsStringAsync());
                    }
                }
            }
        }