Set values for the CURL options

This function allows us to set values for the possible options in the CURL data structure that defines the HTTP request. These options persist across calls in the CURLHandle object.

curlSetOpt(..., .opts = list(), curl = getCurlHandle(),
            .encoding = integer(), .forceHeaderNames = FALSE,
             .isProtected = FALSE)

a named list of curl options to set after the handle has been created.


a named list or CURLOptions object identifying the curl options for the handle.


the CURLHandle object created earlier via a call to getCurlHandle or dupCurlHandle


an integer or a string that explicitly identifies the encoding of the content that is returned by the HTTP server in its response to our query. The possible strings are ‘UTF-8’ or ‘ISO-8859-1’ and the integers should be specified symbolically as CE_UTF8 and CE_LATIN1. Note that, by default, the package attempts to process the header of the HTTP response to determine the encoding. This argument is used when such information is erroneous and the caller knows the correct encoding.


a logical value which if TRUE allows the caller to explicitly indicate that the HTTPHEADER option needs to have the names prefixed to the strings. This removes any ambiguity caused by the presence of ':' in the values appearing to be the separator between the name and the value of the name: value pairs of the HTTP header.


a logical vector (or value that is repeated) specifying which of the values in … and .opts need to be explicitly protected from garbage collection or not. The basic idea is that we specify FALSE if the value being set for the curl option may be garbage collected before the curl handle is garbage collected. This would leave the curl object in an inconsistent state, referring to an R object (i.e. an R function), which may be used after the R object has been garbage collected.


An integer value giving the status of the return. This should be 0 as if there was an error in the libcurl mechiansim, we will throw it there.


Curl homepage

See Also

getCurlHandle dupCurlHandle

  • curlSetOpt
if(url.exists("")) {

  curl = getCurlHandle()
     # Note the header that extends across two lines with the second line
     # prefixed with white space.
   curlSetOpt( .opts = list(httpheader = c(Date = "Wed, 1/2/2000 10:01:01",
                            foo="abc\n    extra line"), verbose = TRUE),
               curl = curl)
   ans = getURL("", curl = curl)
# }
Documentation reproduced from package RCurl, version 1.98-1.1, License: BSD_3_clause + file LICENSE

Community examples

Looks like there are no examples yet.