Sample code for 30+ languages & platforms
C++

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat C++ Downloads

C++
#include <CkHttp.h>

void ChilkatSample(void)
    {
    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    CkHttp http;

    //  To use HTTP Basic authentication:
    http.put_Login("myLogin");
    http.put_Password("myPassword");
    http.put_BasicAuth(true);

    //  Run the test using this URL with the credentials above.  
    //  (Works while httpbin.org keeps the test endpoint available.)
    const char *jsonResponse = http.quickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword");
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Response status code: " << http.get_LastStatus() << "\r\n";

    std::cout << jsonResponse << "\r\n";

    //  Output:

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