skazantsev / WebDavClient

Asynchronous cross-platform WebDAV client for .NET Core
MIT License
155 stars 30 forks source link

Initializing with httpclient gives 401 Unauthorized #62

Closed nickelnext closed 3 years ago

nickelnext commented 3 years ago

Hi

Same user:pass:

If I use WebDavClient result = new WebDavClient(httpClient);, when making PROPFIND i get 401 unauthorized (sometimes the first time, sometimes the second time)

If i use

WebDavClientParams clientParams = new WebDavClientParams { BaseAddress = new Uri(serviceUrl), Credentials = new NetworkCredential(username, password) }; webDavClient = new WebDavClient(clientParams);

Propfind works like a charme.

Note: httpclient has the sameBaseAddressspecified in BaseAddressof WebDavClientParams, and the credentials are the same

Note2: the propfind is made on a folder (not the root folder). I didn't test it on a file

skazantsev commented 3 years ago

Hi @nickelnext ,

I wonder how the httpClient that you're passing in the first example is configured, maybe there's a problem there. If you pass WebDavClientParams the WebDavClient creates & configures HttpClient instance internally.

Here's a code: https://github.com/skazantsev/WebDavClient/blob/master/src/WebDav.Client/WebDavClient.cs#L783

I recommend to play with settings of HttpClientHandler of the HttpClient that you're passing. When using WebDavClientParams the following properties are to true by default: PreAuthenticate, UseDefaultCredentials and these settings are probably false for a new instance of HttpClient.

Hope that helps.

nickelnext commented 3 years ago

I'll check it.

Thanks for your prompt response!