-
Notifications
You must be signed in to change notification settings - Fork 10
/
word.cs
28 lines (21 loc) · 1.1 KB
/
word.cs
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
using System.Text;
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var request = new HttpRequestMessage(HttpMethod.Post, "word"))
{
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
request.Headers.Accept.Add(new("application/json"));
var multipartContent = new MultipartFormDataContent();
var byteArray = File.ReadAllBytes("/path/to/file");
var byteAryContent = new ByteArrayContent(byteArray);
multipartContent.Add(byteAryContent, "file", "file_name");
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf");
var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("converted"));
multipartContent.Add(byteArrayOption, "output");
request.Content = multipartContent;
var response = await httpClient.SendAsync(request);
var apiResult = await response.Content.ReadAsStringAsync();
Console.WriteLine("API response received.");
Console.WriteLine(apiResult);
}
}