Zig
Zig
Example: Http.QuickGetStr method
Demonstrates theQuickGetStr 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();
// Keep the response body if there's an error.
http.setKeepResponseBody(true);
// Send the HTTP GET and return the content in a string.
const str = http.quickGetStr(alloc, "https://www.chilkatsoft.com/helloWorld.json") 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 http.getLastResponseBody(alloc)});
}
return;
};
std.debug.print("{s}\n", .{str});
std.debug.print("Success\n", .{});
}