Source Code File 03-06_curlerror2.c
#include <stdio.h> #include <stdlib.h> #include <curl/curl.h> int main() { CURL *curl; CURLcode res; char url[] = "odd://site.com"; /* Initialize easy curl */ curl = curl_easy_init(); if( curl == NULL) { fprintf(stderr,"Unable to init\n"); exit(1); } /* set options */ curl_easy_setopt(curl, CURLOPT_URL, url); /* curl the resource */ res = curl_easy_perform(curl); if( res!=CURLE_OK ) { fprintf(stderr,"Can't curl %s\n",url); fprintf(stderr,"Error: %s\n", curl_easy_strerror(res) ); exit(1); } /* cleanup */ curl_easy_cleanup(curl); return(0); }
Notes
* The URL used in the url string is invalid.
* Of all the error-reporting methods available in the libcurl library, using the curl_easy_strerror() function is the best.
* Wide version of this code (statements not split)
Copyright © 1997-2024 by QPBC.
All rights reserved