73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Net;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
|
|
namespace SafeSeaNetTest
|
|
{
|
|
class Program
|
|
{
|
|
|
|
private static string baseUri = "https://nswtest.safeseanet.dk/api/v1/search?query=contentType: ship&take=5";
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Login();
|
|
|
|
|
|
Console.Read();
|
|
}
|
|
|
|
private static async void Login()
|
|
{
|
|
NetworkCredential credential = new NetworkCredential("bsm-schick", "Melder2016");
|
|
|
|
/*
|
|
WebRequest req = WebRequest.Create(baseUri);
|
|
req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
|
|
|
|
req.Credentials = credential;
|
|
WebResponse resp = req.GetResponse();
|
|
StreamReader reader = new StreamReader(resp.GetResponseStream());
|
|
var token = reader.ReadToEnd().Trim();
|
|
|
|
Console.WriteLine(token);
|
|
*/
|
|
|
|
// Variante 2
|
|
// Create a network credential with username, password, and damain name
|
|
// var credential = new NetworkCredential("username", "password", "domainname");
|
|
var myCache = new CredentialCache();
|
|
|
|
// Add the target Uri to the CredentialCache with credential object
|
|
myCache.Add(new Uri(baseUri), "NTLM", credential);
|
|
|
|
// Create an HttpClientHandler to add some settings
|
|
var handler = new HttpClientHandler();
|
|
handler.AllowAutoRedirect = true;
|
|
handler.Credentials = myCache;
|
|
|
|
// Create an HttpClient with the handler object
|
|
HttpClient httpClient = new HttpClient(handler);
|
|
|
|
// Wait to get the reponse, and you can use the reponse in your code
|
|
HttpResponseMessage responseMessage = await httpClient.GetAsync(baseUri);
|
|
|
|
string jsonMessage;
|
|
using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync())
|
|
{
|
|
jsonMessage = new StreamReader(responseStream).ReadToEnd();
|
|
}
|
|
|
|
Console.WriteLine(jsonMessage);
|
|
}
|
|
|
|
|
|
}
|
|
}
|