Zig
Zig
POST application/json HTTPS Request
See more HTTP Examples
Demonstrates how to send an HTTPS POST where the request body and response body both have the application/json Content-Type. Also demonstrates how to add a few custom headers to the request.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 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();
// Add a few custom headers.
http.setRequestHeader("Client-ID", "my_client_id");
http.setRequestHeader("Client-Token", "my_client_token");
http.setAccept("application/json");
const url = "https://api.fiscallog.eu/sign/v1";
const json_request_body = "{ .... }";
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("POST", url, json_request_body, "utf-8", "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response status code = {d}\n", .{resp.getStatusCode()});
const json_response_str = try resp.getBodyStr(alloc);
std.debug.print("{s}\n", .{json_response_str});
}