-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteAPI.cs
More file actions
56 lines (47 loc) · 2.03 KB
/
Copy pathRemoteAPI.cs
File metadata and controls
56 lines (47 loc) · 2.03 KB
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
51
52
53
54
55
56
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Adachi_ChatGPT_testing
{
class RemoteAPI
{
private readonly Uri _uri;
private readonly string _username;
private readonly string _password;
public RemoteAPI(Uri uri, string username, string password)
{
_uri = uri;
_username = username;
_password = password;
}
public async Task<string> SendPayload(string payload)
{
// Create a new HttpClient instance
using (HttpClient client = new HttpClient())
{
// Set the remote endpoint URI
client.BaseAddress = _uri;
//add useragent header so i can find meself in logs
client.DefaultRequestHeaders.Add("User-Agent", "Adachi Desktop thingy v0.8");
// Configure SSL/TLS connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
// Set basic authentication header
string authHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_username}:{_password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeader);
// Create a new HTTP POST request with the "Hello World" payload
var content = new StringContent(payload, Encoding.UTF8, "text/plain");
var response = await client.PostAsync("", content);
// Check if the response was successful
response.EnsureSuccessStatusCode();
// Read the response content as a string and return it
return await response.Content.ReadAsStringAsync();
}
}
}
}