Zig
Zig
Inspect HTTP Request Header
Demonstrates theLastHeader property.
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();
const url = "https://chilkatsoft.com/echo_request_body.asp";
const json = "{\"greeting\":\"Hello World\"}";
// Send a POST with the JSON in the HTTP request body.
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("POST", url, json, "utf-8", "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
// Examine the HTTP request header we just sent.
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
// Output:
// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/json
// Content-Length: 26
}