(Unicode C++) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
#include <CkHttpW.h>
void ChilkatSample(void)
{
// This example assumes 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"
// }
}
|