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.

84 lines
2.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: httppost.c,v 1.3 2004/08/26 17:02:24 rans 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. #ifdef WIN32
  26. #include <stdafx.h>
  27. #include <malloc.h>
  28. #else
  29. #include <stdio.h>
  30. #endif
  31. #ifdef WIN32
  32. int _tmain(int argc, _TCHAR* argv[])
  33. #else
  34. int main(int argc, char *argv[])
  35. #endif
  36. {
  37. httpc_conn_t *conn;
  38. hresponse_t *res;
  39. hpair_t *pair;
  40. char postdata[1054];
  41. if (argc < 2) {
  42. fprintf(stderr, "usage %s <url> \n", argv[0]);
  43. exit(1);
  44. }
  45. log_set_level(HLOG_VERBOSE);
  46. printf("\nEnter post data (max 1054): ");
  47. gets(postdata);
  48. printf("\nSending data to '%s'. Please wait ...\n ", argv[1]);
  49. log_debug2("you entered: '%s'", postdata);
  50. log_debug2("content-length: %d", strlen(postdata));
  51. conn = httpc_new();
  52. res = httpc_post(conn, argv[1], strlen(postdata), postdata);
  53. if (res != NULL) {
  54. log_info2("Spec : '%s'", res->spec);
  55. log_info2("Status: %d", res->errcode);
  56. log_info2("Desc : '%s'", res->desc);
  57. if (res->body) {
  58. pair = res->header;
  59. while (pair != NULL) {
  60. log_debug3("%s: %s", pair->key, pair->value);
  61. pair = pair->next;
  62. }
  63. puts(res->body);
  64. }
  65. else
  66. log_error1("body is null");
  67. hresponse_free(res);
  68. } else {
  69. log_error1("response object is null");
  70. }
  71. httpc_free(conn);
  72. return 0;
  73. }