Sample code for 30+ languages & platforms
Unicode C++

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>

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

    CkHttpW http;

    //  To use HTTP Basic authentication:
    http.put_Login(L"myLogin");
    http.put_Password(L"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 wchar_t *jsonResponse = http.quickGetStr(L"https://httpbin.org/basic-auth/myLogin/myPassword");
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"Response status code: %d\n",http.get_LastStatus());

    wprintf(L"%s\n",jsonResponse);

    //  Output:

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