Zig
Zig
Send HTTPS POST with XML Body
See more HTTP Examples
Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML.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();
const str_xml = "<TransactionSetup xmlns=\"https://xyz.com\"><Credentials><AccountID>XXX</AccountID></Credentials></TransactionSetup>";
// Maybe you need other headers?
http.setRequestHeader("Accept", "application/xml");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("POST", "https://www.somewebsite.com/", str_xml, "utf-8", "application/xml", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
// Examine the response status code:
std.debug.print("response status code = {d}\n", .{resp.getStatusCode()});
// Examine the response body:
std.debug.print("response body: {s}\n", .{try resp.getBodyStr(alloc)});
}