Zig
Zig
Demonstrate HttpRequest.RemoveAllParams
Demonstrates the effect of calling HttpRequest.RemoveAllParams.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 req = try chilkat.HttpRequest.init();
defer req.deinit();
req.setHttpVerb("POST");
req.setPath("/test123");
req.setContentType("application/x-www-form-urlencoded");
req.addParam("paramA", "AAA");
req.addParam("paramB", "BBB");
req.addParam("paramC", "CCC");
std.debug.print("{s}\n", .{try req.generateRequestText(alloc)});
std.debug.print("---------------\n", .{});
// Generates:
// POST /test123 HTTP/1.1
// Content-Type: application/x-www-form-urlencoded
// Host: domain
// Content-Length: 32
//
// paramA=AAA¶mB=BBB¶mC=CCC
//
// If we call RemoveAllParams, and then add some additional params,
// then the original params are gone, and only the new params exist.
req.removeAllParams();
req.addParam("paramD", "DDD");
req.addParam("paramE", "EEE");
req.addParam("paramF", "FFF");
std.debug.print("{s}\n", .{try req.generateRequestText(alloc)});
std.debug.print("---------------\n", .{});
// Generates:
// POST /test123 HTTP/1.1
// Content-Type: application/x-www-form-urlencoded
// Host: domain
// Content-Length: 32
//
// paramD=DDD¶mE=EEE¶mF=FFF
}