wip: Http client
This commit is contained in:
27
src/main.zig
27
src/main.zig
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user