-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctranslate
50 lines (44 loc) · 2.24 KB
/
doctranslate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Doctanslate
{
//Program to convert one language to another
class Program
{
static readonly string route = "/batches";
static readonly string endpoint = "https://doclangtranslator.cognitiveservices.azure.com/translator/text/batch/v1.0";
static readonly string key = "26d5286d05d04497b2e0cec784773312";
static readonly string json = ("" +
"{\"inputs\": " +
"[{\"source\": " +
"{\"sourceUrl\": \"https://doctranscionstorage.blob.core.windows.net/inputdocs?sp=r&st=2022-03-08T14:35:25Z&se=2022-03-08T22:35:25Z&spr=https&sv=2020-08-04&sr=c&sig=PI49FV0fdarbsn8ouVQqKqTnryLI4ZLUVudMKveRSKE%3D\"," +
"\"storageSource\": \"AzureBlob\"" +
"}," +
"\"targets\": " +
"[{\"targetUrl\": \"https://doctranscionstorage.blob.core.windows.net/translateddocs?sp=r&st=2022-03-08T14:37:32Z&se=2022-03-08T22:37:32Z&spr=https&sv=2020-08-04&sr=c&sig=TcJJydxKi6tChJJ7e%2BE79oFr4%2FZCDE%2Fv2K4QmdoJyYA%3D\"," +
"\"storageSource\": \"AzureBlob\"," +
"\"language\": \"fr\"}]}]}");
static async Task Main(string[] args)
{
using HttpClient client = new HttpClient();
using HttpRequestMessage request = new HttpRequestMessage();
{
StringContent data = new StringContent(json, Encoding.UTF8, "application/json");
request.Method = HttpMethod.Post;
request.RequestUri = new Uri(endpoint + route);
request.Headers.Add("Ocp-Apim-Subscription-Key", key);
request.Content = data;
HttpResponseMessage response = await client.SendAsync(request);
string result = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine($ "Operation successful with status code: {response.StatusCode}");
}
else
Console.Write($ "Error occurred. Status code: {response.StatusCode}");
}
}
}
}