69 lines
2.6 KiB
C#
69 lines
2.6 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FabitArchiwum.Test
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var sha1 = System.Security.Cryptography.SHA1.Create();
|
|
var pwd = sha1.ComputeHash(Encoding.UTF8.GetBytes("krfkrf"));
|
|
Console.WriteLine(BitConverter.ToString(pwd).Replace("-","").ToLower());
|
|
Console.ReadLine();
|
|
const String WEBAPI_URL = "https://localhost:32787";
|
|
var handler = new HttpClientHandler();
|
|
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
|
|
handler.ServerCertificateCustomValidationCallback =
|
|
(httpRequestMessage, cert, cetChain, policyErrors) =>
|
|
{
|
|
return true;
|
|
};
|
|
|
|
using (var client = new HttpClient(handler))
|
|
{
|
|
String user = "krf";
|
|
String password = "krfkrf";
|
|
|
|
var data = new StringContent(JsonConvert.SerializeObject(new
|
|
{
|
|
username = "krf",
|
|
password = "krfkrf"
|
|
}));
|
|
data.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
|
|
try
|
|
{
|
|
var response = client.PostAsync("https://192.168.0.99:5555/api/Authenticate/Login", data).Result;
|
|
var resp = response.Content.ReadAsStringAsync().Result;
|
|
Console.WriteLine(resp);
|
|
var tokenModel = JsonConvert.DeserializeObject<Model.TokenModel>(resp);
|
|
Console.ReadLine();
|
|
|
|
using (var client2 = new HttpClient(handler))
|
|
{
|
|
client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenModel.token);
|
|
|
|
var response2 = client2.GetAsync("https://192.168.0.99:5555/api/Archiwum/GetTree").Result;
|
|
var resp2 = response2.Content.ReadAsStringAsync().Result;
|
|
Console.WriteLine(resp2);
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message+ex.StackTrace+ex.InnerException);
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|