Perform the HTTP query
curlPerform.RdThese function causes the HTTP query, that has been specified
via the different options in this and other calls, to be sent and processed.
Unlike in curl itself,
for curlPerform one can specify all the options
in this call as an atomic invocation.
This avoids having to set the options and then perform
the action. Instead, this is all done in one call.
For curlMultiPerform, one must add the relevant
CURLHandle-class objects to the
MultiCURLHandle-class objects
before issuing the call to curlMultiPerform.
Usage
curlPerform(..., .opts = list(), curl = getCurlHandle(), .encoding = integer())
curlMultiPerform(curl, multiple = TRUE)Arguments
- curl
for
curlPerform, this is theCURLHandleobject giving the structure for the options and that will process the command. ForcurlMultiPerform, this is an object of class codeMultiCURLHandle-class.- ...
a named list of curl options to set after the handle has been created.
- .opts
a named list or
CURLOptionsobject identifying the curl options for the handle. This is merged with the values of ... to create the actual options for the curl handle in the request.- multiple
a logical value. If
TRUEand the internal call tocurl_multi_performreturns a value that indicates there is still data available from one of the HTTP responses, we callcurl_multi_performrepeatedly until there is no more data available at that time. If this isFALSE, we callcurl_multi_performonce and return, regardless of whether there is more data available. This is convenient if we want to limit the time spent in the call tocurlMultiPerform.- .encoding
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_UTF8andCE_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.Note that the encoding argument is not a regular libcurl option and is handled specially by RCurl. But as a result, it is not unset in subsequent uses of the curl handle (
curl).
Value
A integer value indicating the status of the request. This should be 0 as other errors will generate errors.
References
Curl homepage https://curl.se/
Examples
tryCatch(withAutoprint({
h = basicTextGatherer()
curlPerform(url = "https://r-project.org", writefunction = h$update)
# Now read the text that was cumulated during the query response.
cat(h$value())
}), GenericCurlError = identity)
#> > h = basicTextGatherer()
#> > curlPerform(url = "https://r-project.org", writefunction = h$update)
#> OK
#> 0
#> > cat(h$value())
#> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
#> <html><head>
#> <title>301 Moved Permanently</title>
#> </head><body>
#> <h1>Moved Permanently</h1>
#> <p>The document has moved <a href="https://www.r-project.org/">here</a>.</p>
#> <hr>
#> <address>Apache Server at r-project.org Port 443</address>
#> </body></html>
if (FALSE) { # \dontrun{
## this no longer exists
if(url.exists("http://services.soaplite.com/hibye.cgi")) withAutoprint({
# SOAP request
body = '<?xml version="1.0" encoding="UTF-8"?>\
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" \
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/1999/XMLSchema" \
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" \
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">\
<SOAP-ENV:Body>\
<namesp1:hi xmlns:namesp1="http://www.soaplite.com/Demo"/>\
</SOAP-ENV:Body>\
</SOAP-ENV:Envelope>\n'
h$reset()
curlPerform(url = "http://services.soaplite.com/hibye.cgi",
httpheader=c(Accept="text/xml", Accept="multipart/*",
SOAPAction='"http://www.soaplite.com/Demo#hi"',
'Content-Type' = "text/xml; charset=utf-8"),
postfields=body,
writefunction = h$update,
verbose = TRUE
)
body = h$value()
})
} # }
# Using a C routine as the reader of the body of the response.
tryCatch(withAutoprint({
routine = getNativeSymbolInfo("R_internalWriteTest", PACKAGE = "RCurl")$address
curlPerform(URL = "https://r-project.org",
writefunction = routine)
}), GenericCurlError = identity)
#> > routine = getNativeSymbolInfo("R_internalWriteTest", PACKAGE = "RCurl")$address
#> > curlPerform(URL = "https://r-project.org", writefunction = routine)
#> <R_internalWrite> size = 1, nmemb = 338
#> OK
#> 0