-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebAPI.cs
42 lines (36 loc) · 1.37 KB
/
WebAPI.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace HashServer
{
public class WebAPI
{
static readonly HttpClient client;
static WebAPI()
{
client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.MaxResponseContentBufferSize = 1024 * 1024;
client.BaseAddress = new Uri(Program.Settings.External.gRoot);
}
public async static Task<HttpResponseMessage> POST(string data, string uri = "https://pdb2json.azurewebsites.net/api/PageHash/x")
{
var response = await client.PostAsync(uri, new StringContent(data, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
return response;
}
public async static Task ProxyObject(string data, Stream writeTo, string uri = "https://pdb2json.azurewebsites.net/api/PageHash/x")
{
var response = await client.PostAsync(uri, new StringContent(data, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
await response.Content.CopyToAsync(writeTo);
}
}
}