Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Authentication not work #88

Open
maza70 opened this issue Sep 21, 2023 · 0 comments
Open

Basic Authentication not work #88

maza70 opened this issue Sep 21, 2023 · 0 comments

Comments

@maza70
Copy link

maza70 commented Sep 21, 2023

Can't use the http Basic-Authentication the statuscode is always System.Net.HttpStatusCode.Unauthorized.
With the normal MessageHandler the code works.
How to use the http Basic Authentification?

Thanks for your support!

Sample Code:

try
{
	var tlsConfig = new TLSConfig()
	{
		DangerousAcceptAnyServerCertificateValidator = true,
		Pins = new List<Pin>()
				{
					new Pin()
					{
						Hostname = "*",
						PublicKeys=new string[]{ }
					}
				}

	};
	var handler = new NativeMessageHandler(false, tlsConfig);

	HttpClient client = new HttpClient(handler);

	var webdavUrl = new Uri("https://ubuntu/remote.php/dav/files/zpush");
	var passwordCache = new CredentialCache();
	passwordCache.Add(webdavUrl, "Basic", new NetworkCredential("xxx", "secret"));
	handler.Credentials = passwordCache;
	handler.UseDefaultCredentials = false;
	handler.PreAuthenticate = true;


	var request = new HttpRequestMessage(new HttpMethod("PROPFIND"), webdavUrl);
	var response = await client.SendAsync(request, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
	var satuscode = response.StatusCode;

}
catch (Exception ex)
{
	Console.WriteLine(ex.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant