lib651.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "test.h"
  23. #include "memdebug.h"
  24. static char buffer[17000]; /* more than 16K */
  25. int test(char *URL)
  26. {
  27. CURL *curl;
  28. CURLcode res = CURLE_OK;
  29. CURLFORMcode formrc;
  30. struct curl_httppost *formpost = NULL;
  31. struct curl_httppost *lastptr = NULL;
  32. /* create a buffer with AAAA...BBBBB...CCCC...etc */
  33. int i;
  34. int size = (int)sizeof(buffer)/1000;
  35. for(i = 0; i < size ; i++)
  36. memset(&buffer[i * 1000], 65 + i, 1000);
  37. buffer[ sizeof(buffer)-1] = 0; /* null-terminate */
  38. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  39. fprintf(stderr, "curl_global_init() failed\n");
  40. return TEST_ERR_MAJOR_BAD;
  41. }
  42. /* Check proper name and data copying. */
  43. formrc = curl_formadd(&formpost, &lastptr,
  44. CURLFORM_COPYNAME, "hello",
  45. CURLFORM_COPYCONTENTS, buffer,
  46. CURLFORM_END);
  47. if(formrc)
  48. printf("curl_formadd(1) = %d\n", (int) formrc);
  49. curl = curl_easy_init();
  50. if(!curl) {
  51. fprintf(stderr, "curl_easy_init() failed\n");
  52. curl_formfree(formpost);
  53. curl_global_cleanup();
  54. return TEST_ERR_MAJOR_BAD;
  55. }
  56. /* First set the URL that is about to receive our POST. */
  57. test_setopt(curl, CURLOPT_URL, URL);
  58. /* send a multi-part formpost */
  59. test_setopt(curl, CURLOPT_HTTPPOST, formpost);
  60. /* get verbose debug output please */
  61. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  62. /* include headers in the output */
  63. test_setopt(curl, CURLOPT_HEADER, 1L);
  64. /* Perform the request, res will get the return code */
  65. res = curl_easy_perform(curl);
  66. test_cleanup:
  67. /* always cleanup */
  68. curl_easy_cleanup(curl);
  69. /* now cleanup the formpost chain */
  70. curl_formfree(formpost);
  71. curl_global_cleanup();
  72. return res;
  73. }