demo_wget.c 696 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <gmssl/http.h>
  13. #include <gmssl/error.h>
  14. int main(int argc, char **argv)
  15. {
  16. uint8_t buf[65536];
  17. uint8_t *content;
  18. size_t contentlen;
  19. if (argc < 2) {
  20. printf("usage: %s <uri>\n", argv[0]);
  21. return 1;
  22. }
  23. if (http_get(argv[1], buf, sizeof(buf), &content, &contentlen) != 1) {
  24. error_print();
  25. return -1;
  26. }
  27. fwrite(content, contentlen, 1, stdout);
  28. return 0;
  29. }