Sample code for 30+ languages & platforms
C#

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat C# Downloads

C#
//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

Chilkat.Http http = new Chilkat.Http();

//  To use HTTP Basic authentication:
http.Login = "myLogin";
http.Password = "myPassword";
http.BasicAuth = true;

//  Run the test using this URL with the credentials above.  
//  (Works while httpbin.org keeps the test endpoint available.)
string jsonResponse = http.QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword");
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Debug.WriteLine("Response status code: " + Convert.ToString(http.LastStatus));

Debug.WriteLine(jsonResponse);

//  Output:

//  Response status code: 200
//  {
//    "authenticated": true, 
//    "user": "myLogin"
//  }