wip: Http client

This commit is contained in:
2025-03-28 09:11:36 +01:00
parent dc14a7cb1c
commit 960d54a433

View File

@@ -37,6 +37,33 @@ export fn main() c_int {
// } // }
// _ = p.printf("Hello world\n"); // _ = p.printf("Hello world\n");
std.options.page_size_max = 4096;
// Create a general purpose allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
// Create a HTTP client
var client = std.http.Client{ .allocator = gpa.allocator() };
defer client.deinit();
// Allocate a buffer for server headers
var buf: [4096]u8 = undefined;
// Start the HTTP request
const uri = try std.Uri.parse("https://www.google.com?q=zig");
var req = try client.open(.GET, uri, .{ .server_header_buffer = &buf });
defer req.deinit();
// Send the HTTP request headers
try req.send();
// Finish the body of a request
try req.finish();
// Waits for a response from the server and parses any headers that are sent
try req.wait();
std.debug.print("status={d}\n", .{req.response.status});
while (true) { while (true) {
while (p.gpio_get(BUTTON_PIN)) { while (p.gpio_get(BUTTON_PIN)) {
p.cyw43_arch_gpio_put(p.CYW43_WL_GPIO_LED_PIN, true); p.cyw43_arch_gpio_put(p.CYW43_WL_GPIO_LED_PIN, true);