-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathpost.zig
More file actions
38 lines (33 loc) · 1017 Bytes
/
Copy pathpost.zig
File metadata and controls
38 lines (33 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const std = @import("std");
const curl = @import("curl");
pub fn main(init: std.process.Init) !void {
var gpa = std.heap.DebugAllocator(.{}){};
defer if (gpa.deinit() != .ok) @panic("leak");
const allocator = gpa.allocator();
const ca_bundle = try curl.allocCABundle(allocator, init.io);
defer ca_bundle.deinit();
var easy = try curl.Easy.init(.{
.ca_bundle = ca_bundle,
});
defer easy.deinit();
const payload =
\\{"name": "John", "age": 15}
;
var writer = std.Io.Writer.Allocating.init(allocator);
defer writer.deinit();
const resp = try easy.fetch(
"https://edgebin.liujiacai.net/anything",
.{
.method = .POST,
.body = payload,
.headers = &.{
"Content-Type: application/json",
},
.writer = &writer.writer,
},
);
std.debug.print("Status code: {d}\nBody: {s}\n", .{
resp.status_code,
writer.writer.buffered(),
});
}