dir.by  
Поиск >>

Компьютер, программы
→
Microsoft Azure & Azure DevOps (cloud)
 Write a C# console application to translate text using Azure Translators 
посмотрели 7638 раз
обновлено: 17 April 2024
  C#     Program.cs
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json; // Install Newtonsoft.Json with NuGet

namespace ConsoleApp1
{
     class Program
     {
          // my settings !!!
          private static readonly string endpoint = "https://api.cognitive.microsofttranslator.com/";
          private static readonly string subscriptionKey = "568af7141d8e4f309f712d.............";
          private static readonly string location = "westeurope";

          // program
          static async Task Main(string[] args)
          {
               // Input and output languages are defined as parameters.
               string route = "/translate?api-version=3.0&from=en&to=de&to=it";
               string textToTranslate = "Hello, world!";
               object[] body = new object[] { new { Text = textToTranslate } };
               var requestBody = JsonConvert.SerializeObject(body);

               using (var client = new HttpClient())
               using (var request = new HttpRequestMessage())
               {
                    // Build the request.
                    request.Method = HttpMethod.Post;
                    request.RequestUri = new Uri(endpoint + route);
                    request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
                    request.Headers.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
                    request.Headers.Add("Ocp-Apim-Subscription-Region", location);

                    // Send the request and get response.
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
                    // Read response as a string.
                    string result = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(result);
               }
          }
     }
}
Example result
"endpoint", "subscriptionKey", "location" we take from here:
 
← Previous topic
Create Azure Translators (to translate text)
 
Next topic →
Azure Translator error "is disabled and therefore marked as read only. You cannot perform any write actions on this subscription until it is re-enabled"
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
Azure
• What is Microsoft Azure?
• How do I create a service in Azure?
<BR>Azure (Subscription)
• Create a Subscription in Azure
• How do I see my costs (how much money to pay per month, pay) in Azure?
• How to change the billing card number in Azure
<BR>Install Microsoft Authenticator on your phone
• Install Microsoft Authenticator on your phone and sign in to your account
<BR>Azure (Resource Group)
• Create a Resource Group in Azure
<BR>Azure (SQL Server)
• Build SQL Server in Azure
• Writing a C# program to use an Azure SQL Server database
• Save the SQL Server Azure database to your computer (backup)
• In SQL Server Azure Database, we set the cheapest price ($6 per month Basic)
<BR>Azure (Web service) for .Net Core 5.0 applications
• Create an Azure Web service with a Net Core 5 type. That is, we create an empty web server with the Net Core 5 type
• .Net Core 5 Web API app publish to Azure → | Using Visual Studio 2019
• Connect to the .NET Core 5 Web API (Azure Web Service) application via FTP | use FAR, File Explorer
Azure (Web App) for Angular 9.0 applications
• Creating an Azure Web Service for the Angular application. That is, create an empty web server
• Angular web application do publish to → Azure | use Visual Studio Code
• Connect to the Angular (Azure Web Service) application via FTP | use FAR, File Explorer
Azure Translators (Translator)
• Create Azure Translators (to translate text)
• Write a C# console application to translate text using Azure Translators
• Azure Translator error "is disabled and therefore marked as read only. You cannot perform any write actions on this subscription until it is re-enabled"
Twilio SendGrid (email)
• Create an Azure Twilio SendGrid (to send emails)
• Open Twilio SendGrid from Azure. Create an ApiKey. Writing a C# application to send an email
<BR>
FTPS Server on Azure
• FTPS Server on Azure
<BR>
Teams plug-in application
• Microsoft Teams web application (plug-in)" using React
• Creating an Azure Web Service for React Teams web application. That is, create an empty web server
• Appendix. Microsoft Teams web application publish to → Azure | use Visual Studio Code
• Upload app in teams
<BR>
Add a user
• Add a new user and make the user have access to the Subscription
Azure DevOps
• What is Azure DevOps?
<BR>
In DevOps, we create an organization. We create projects
• Get started with Azure DevOps. Creating an organization. Create a project (git repository)
<BR>
In DevOps, we invite the user
• In DevOps, we invite the user
• In DevOps, assign privileges to the invited user (so that the invited user can log in to DevOps)
<BR>
More about DevOps
• Azure DevOps pricing
• Sign in to Azure DevOps from the Chrome browser
• What does Azure DevOps contain in the Chrome browser?
• Azure DevOps. Commit files to git using Team Explorer in Visual Studio 2017
• Azure DevOps. How to add a link to git commit to a bug (using commit hash)

  Ваши вопросы присылайте по почте: info@dir.by