// copy URL into a buffer, as the GAP string could be moved // by a garbage collection triggered by write_string
len = GET_LEN_STRING(URL) + 1; if (len > sizeof(urlbuf)) {
ErrorMayQuit("CURL_REQUEST: must be less than %d chars", sizeof(urlbuf), 0L);
}
memcpy(urlbuf, CONST_CSTR_STRING(URL), len);
res = curl_global_init(CURL_GLOBAL_DEFAULT); if (res != 0) {
ErrorMayQuit("CURL_REQUEST: failed to initialize libcurl (error %d)",
(Int)res, 0L);
}
if (verbose == True)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
if (followRedirect == True)
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
if (failOnError == True)
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
if (maxTime != 0)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, maxTime);
if (strcmp(CONST_CSTR_STRING(type), "GET") == 0) { // simply download from the URL
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
} elseif (strcmp(CONST_CSTR_STRING(type), "POST") == 0) { // send a string to the URL
len = GET_LEN_STRING(out_string); // no null character
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, len);
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS,
CONST_CSTR_STRING(out_string)); // using COPYPOSTFIELDS copies the data right now
} elseif (strcmp(CONST_CSTR_STRING(type), "HEAD") == 0) { // only get headers, without body
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
} else { // custom request e.g. DELETE
len = GET_LEN_STRING(type) + 1; // include null character
typebuf = (char *) malloc(len);
memcpy(typebuf, CONST_CSTR_STRING(type), len);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, typebuf);
}
if (verifyCert == True) { // // If you want to connect to a site who isn't using a certificate // that is signed by one of the certs in the CA bundle you have, // you can skip the verification of the server's certificate. This // makes the connection A LOT LESS SECURE. // // If you have a CA cert for the server stored someplace else than // in the default bundle, then the CURLOPT_CAPATH option might // come handy for you. //
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
// // If the site you're connecting to uses a different host name // that what they have mentioned in their server certificate's // commonName (or subjectAltName) fields, libcurl will refuse to // connect. You can skip this check, but this will make the // connection less secure. //
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
}
// Perform the request, res will get the return code
res = curl_easy_perform(curl);
// Check for errors if (res != CURLE_OK) { if (*errbuf)
errorstring = MakeImmString(errbuf); else
errorstring = MakeImmString(curl_easy_strerror(res));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.