| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <glib.h> | ||
| 2 | #include <curl/curl.h> | ||
| 3 | #include "examples/curl.h" | ||
| 4 | |||
| 5 | ✗ | extern int curl_example() { | |
| 6 | CURL* curl; | ||
| 7 | |||
| 8 | ✗ | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); | |
| 9 | ✗ | if (res) | |
| 10 | ✗ | return (int)res; | |
| 11 | |||
| 12 | ✗ | curl = curl_easy_init(); | |
| 13 | ✗ | if (curl) { | |
| 14 | ✗ | curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); | |
| 15 | /* example.com is redirected, so we tell libcurl to follow redirection | ||
| 16 | */ | ||
| 17 | ✗ | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | |
| 18 | |||
| 19 | /* Perform the request, res gets the return code */ | ||
| 20 | ✗ | res = curl_easy_perform(curl); | |
| 21 | /* Check for errors */ | ||
| 22 | ✗ | if (res != CURLE_OK) | |
| 23 | ✗ | g_printerr("curl_easy_perform() failed: %s\n", | |
| 24 | curl_easy_strerror(res)); | ||
| 25 | |||
| 26 | /* always cleanup */ | ||
| 27 | ✗ | curl_easy_cleanup(curl); | |
| 28 | } | ||
| 29 | ✗ | curl_global_cleanup(); | |
| 30 | ✗ | return 0; | |
| 31 | } | ||
| 32 |