Zig
Zig
Example: Http.QuickGetSb method
Demonstrates theQuickGetSb method.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const http = try chilkat.Http.init();
defer http.deinit();
// Send the HTTP GET and return the content in a StringBuilder
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
http.quickGetSb("https://www.chilkatsoft.com/helloWorld.json", sb) catch {
if (http.getLastStatus() == 0) {
// Communications error. We did not get a response.
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
std.debug.print("Response status code: {d}\n", .{http.getLastStatus()});
std.debug.print("Response body error text:\n", .{});
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
}
return;
};
// The downloaded content:
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
std.debug.print("Success\n", .{});
}