You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: httpget.c,v 1.4 2004/09/19 07:05:03 snowdrop Exp $
  3. *
  4. * CSOAP Project: A http client/server library in C (example)
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammer.net
  23. ******************************************************************/
  24. #include <nanohttp/nanohttp-client.h>
  25. #include <stdio.h>
  26. int main(int argc, char *argv[])
  27. {
  28. httpc_conn_t *conn;
  29. hresponse_t *res;
  30. hpair_t *pair;
  31. if (argc < 2) {
  32. fprintf(stderr, "usage %s <url>\n", argv[0]);
  33. exit(1);
  34. }
  35. log_set_level(HLOG_VERBOSE);
  36. if (httpc_init(argc, argv))
  37. {
  38. log_error1("Can not init httpc");
  39. return 1;
  40. }
  41. conn = httpc_new();
  42. res = httpc_get(conn, argv[1]);
  43. if (res != NULL) {
  44. log_info2("Spec : '%s'", res->spec);
  45. log_info2("Status: %d", res->errcode);
  46. log_info2("Desc : '%s'", res->desc);
  47. if (res->body) {
  48. pair = res->header;
  49. while (pair != NULL) {
  50. log_debug3("%s: %s", pair->key, pair->value);
  51. pair = pair->next;
  52. }
  53. puts(res->body);
  54. }
  55. else
  56. log_error1("body is null");
  57. hresponse_free(res);
  58. } else {
  59. log_error1("response object is null");
  60. }
  61. httpc_free(conn);
  62. return 0;
  63. }