Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add basic authentication header to WebRequest [duplicate]

People also ask

How do I add basic authentication?

In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Security, and then select Basic Authentication. Click OK. Click Close.

How do you pass basic authentication in header in Fiddler?

Creating a Basic Authentication RequestSelect the Composer tab. Set the HTTP/HTTPS method to GET and add the URL in the URL field. Create an object in the request Body and the user and passwd variables and their values. In this object, user and passwd are the predefined variables for the Basic Authentication.

How do I get basic authentication in header curl?

To send basic auth credentials with Curl, use the "-u login: password" command-line option. Curl automatically converts the login: password pair into a Base64-encoded string and adds the "Authorization: Basic [token]" header to the request.


Easy. In order to add a basic authentication to your HttpRequest you do this:

string username = "Your username";
string password = "Your password";

string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password));

request.Headers.Add("Authorization", "Basic " + svcCredentials);

In basic authentication you need to use Base64 to encode the credentials.