Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I have a requirement to access a connected printer device through their embedded web server.
The device had an option to secure its details using username and password.
Once it is set, we can only communicate through "https" to that device.
Also there is windows credentials popup will come from UWP app once we initiate communication through https and wait for the user to enter the correct username and password as in web server.

My requirement is we need to pass those credentials as authorization header for a POST request to that device.

eg:-
Authorization: Basic YWRtaW46MTIzNDU2Nzg5


How to access those Windows credentials in UWP app. Without this authorization token, i am getting HTTP:401 unauthorized error for the POST request.


Please guide me to resolve this issue.

Regards
Spk

What I have tried:

I tried hard coding the username and password entered in the web server.
var username = usrName;
                   var password = pwd;
                   var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
                   _httpClient.AuthorizationHeader = new KeyValuePair<string, string>("Basic", base64String);


then in this case the POST request is successful.

Also tried the same in a separate test application. In that case after entering the credentials in the windows credentials popup the same POST request is again sending automatically with those credentials as Basic auth token.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900