etlegacy-libs/curl/docs/examples/urlapi.c

73 lines
2 KiB
C
Raw Normal View History

2012-06-01 15:23:17 +00:00
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
2019-01-03 15:09:10 +00:00
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
2012-06-01 15:23:17 +00:00
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
2016-09-16 04:29:17 +00:00
* are also available at https://curl.haxx.se/docs/copyright.html.
2012-06-01 15:23:17 +00:00
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
2016-09-16 04:29:17 +00:00
/* <DESC>
2019-01-03 15:09:10 +00:00
* Set working URL with CURLU *.
2016-09-16 04:29:17 +00:00
* </DESC>
*/
2012-06-01 15:23:17 +00:00
#include <stdio.h>
#include <curl/curl.h>
2019-01-03 15:09:10 +00:00
#if !CURL_AT_LEAST_VERSION(7, 62, 0)
#error "this example requires curl 7.62.0 or later"
#endif
2012-06-01 15:23:17 +00:00
int main(void)
{
CURL *curl;
CURLcode res;
2019-01-03 15:09:10 +00:00
CURLU *urlp;
CURLUcode uc;
2012-06-01 15:23:17 +00:00
2019-01-03 15:09:10 +00:00
/* get a curl handle */
2012-06-01 15:23:17 +00:00
curl = curl_easy_init();
2019-01-03 15:09:10 +00:00
/* init Curl URL */
urlp = curl_url();
uc = curl_url_set(urlp, CURLUPART_URL,
"http://example.com/path/index.html", 0);
2016-09-16 04:29:17 +00:00
2019-01-03 15:09:10 +00:00
if(uc) {
fprintf(stderr, "curl_url_set() failed: %in", uc);
goto cleanup;
}
2012-06-01 15:23:17 +00:00
2019-01-03 15:09:10 +00:00
if(curl) {
/* set urlp to use as working URL */
curl_easy_setopt(curl, CURLOPT_CURLU, urlp);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
2016-09-16 04:29:17 +00:00
2012-06-01 15:23:17 +00:00
res = curl_easy_perform(curl);
2016-09-16 04:29:17 +00:00
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
2012-06-01 15:23:17 +00:00
2019-01-03 15:09:10 +00:00
goto cleanup;
2012-06-01 15:23:17 +00:00
}
2019-01-03 15:09:10 +00:00
cleanup:
curl_url_cleanup(urlp);
curl_easy_cleanup(curl);
2012-06-01 15:23:17 +00:00
return 0;
}