Zig
Zig
HTTP Basic Authentication Test
Demonstrates how to do HTTP basic authentication using Chilkat.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// To use HTTP Basic authentication:
http.setLogin("myLogin");
http.setPassword("myPassword");
http.setBasicAuth(true);
// Run the test using this URL with the credentials above.
// (Works while httpbin.org keeps the test endpoint available.)
const json_response = http.quickGetStr(alloc, "https://httpbin.org/basic-auth/myLogin/myPassword") catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response status code: {d}\n", .{http.getLastStatus()});
std.debug.print("{s}\n", .{json_response});
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }
}