1 #include <libubox/blobmsg.h>
7 static void example_header_done(struct uclient *cl)
12 printf("Headers (%d): \n", cl->status_code);
13 blobmsg_for_each_attr(cur, cl->meta, rem) {
14 printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
17 printf("Contents:\n");
20 static void example_read_data(struct uclient *cl)
26 len = uclient_read(cl, buf, sizeof(buf));
30 write(STDOUT_FILENO, buf, len);
34 static void example_request_sm(struct uclient *cl)
41 uclient_http_set_request_type(cl, "HEAD");
46 uclient_http_set_request_type(cl, "GET");
56 static void example_eof(struct uclient *cl)
60 if (retries < 10 && uclient_http_redirect(cl)) {
66 example_request_sm(cl);
69 static const struct uclient_cb cb = {
70 .header_done = example_header_done,
71 .data_read = example_read_data,
72 .data_eof = example_eof,
75 int main(int argc, char **argv)
80 fprintf(stderr, "Usage: %s <URL>\n", argv[0]);
85 cl = uclient_new(argv[1], &cb);
87 fprintf(stderr, "Failed to allocate uclient context\n");
90 example_request_sm(cl);