anaisbetts / ModernHttpClient

HttpClient implementations that use platform-native HTTP clients for :rocket:
MIT License
662 stars 263 forks source link

Authorization Required even though credentials are provided #205

Open PhilippC opened 8 years ago

PhilippC commented 8 years ago

I am executing the following code:

 var ioc = new IOConnectionInfo()
        {
            Path = "https://webdav.mc.gmx.net/file.txt",
            UserName = [my user name],
            Password = [my password]
        };

        {
            var handler = new HttpClientHandler();
            handler.Credentials = new NetworkCredential(ioc.UserName, ioc.Password);

            var httpClient = new HttpClient(handler);
            using (Stream stream = httpClient.GetStreamAsync(ioc.Path).Result)
            {
                Android.Util.Log.Debug("KP2AT", "HttpClientHandler works.");
            }
        }

        {
            var handler = new NativeMessageHandler();
            handler.Credentials = new NetworkCredential(ioc.UserName, ioc.Password);

            var httpClient = new HttpClient(handler);
            using (Stream stream = httpClient.GetStreamAsync(ioc.Path).Result)
            {
                Android.Util.Log.Debug("KP2AT", "NativeMessageHandler works.");
            }
        }

The first log message (HttpClientHandler works) is written out, the second is not because of an exception: System.Net.Http.HttpRequestException : 401 (Authorization Required)

Is there anything wrong in my code? Why is NativeMessageHandler no "Drop-In-Replacement" as "advertised" here?

Cheesebaron commented 8 years ago

NetworkCredential doesn't seem to be used anywhere. So this might be a feature not supported yet.

PhilippC commented 8 years ago

Is there any other way to pass credentials then? Am 29.02.2016 13:42 schrieb "Tomasz Cielecki" notifications@github.com:

NetworkCredential doesn't seem to be used anywhere. So this might be a feature not supported yet.

— Reply to this email directly or view it on GitHub https://github.com/paulcbetts/ModernHttpClient/issues/205#issuecomment-190195301 .

Cheesebaron commented 8 years ago

You could just set the header?

Maybe something like this: http://stackoverflow.com/a/6239579/368379

PhilippC commented 8 years ago

I was planning to use a WebDAV Client implementation (built on top of HttpClient) and thought I could just replace the handler, but it looks like this is not the case.

Am 29.02.2016 um 14:31 schrieb Tomasz Cielecki:

You could just set the header?

Maybe something like this: http://stackoverflow.com/a/6239579/368379

— Reply to this email directly or view it on GitHub https://github.com/paulcbetts/ModernHttpClient/issues/205#issuecomment-190211973.

julesx commented 8 years ago

does setting the Credentials object on the NativeMessageHandler really just do absolutely nothing?