2
0

urlapi.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /* <DESC>
  23. * Set working URL with CURLU *.
  24. * </DESC>
  25. */
  26. #include <stdio.h>
  27. #include <curl/curl.h>
  28. #if !CURL_AT_LEAST_VERSION(7, 62, 0)
  29. #error "this example requires curl 7.62.0 or later"
  30. #endif
  31. int main(void)
  32. {
  33. CURL *curl;
  34. CURLcode res;
  35. CURLU *urlp;
  36. CURLUcode uc;
  37. /* get a curl handle */
  38. curl = curl_easy_init();
  39. /* init Curl URL */
  40. urlp = curl_url();
  41. uc = curl_url_set(urlp, CURLUPART_URL,
  42. "http://example.com/path/index.html", 0);
  43. if(uc) {
  44. fprintf(stderr, "curl_url_set() failed: %in", uc);
  45. goto cleanup;
  46. }
  47. if(curl) {
  48. /* set urlp to use as working URL */
  49. curl_easy_setopt(curl, CURLOPT_CURLU, urlp);
  50. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  51. res = curl_easy_perform(curl);
  52. /* Check for errors */
  53. if(res != CURLE_OK)
  54. fprintf(stderr, "curl_easy_perform() failed: %s\n",
  55. curl_easy_strerror(res));
  56. goto cleanup;
  57. }
  58. cleanup:
  59. curl_url_cleanup(urlp);
  60. curl_easy_cleanup(curl);
  61. return 0;
  62. }