So, if you promise to not let the hack be permanent…
Let's mock an API call by creating a function that calls httr::GET()
:
getƒ <- function() {
httr::GET("comtrade.un.org")
}
Now, we'll make the API call:
getƒ()
## Error in curl::curl_fetch_memory(url, handle = handle) :
## SSL certificate problem: certificate has expired
DOH!
Let's see if there are any {curl} options to help us out:
str(as.list(curl::curl_options("ssl_ver")))
## List of 5
## $ proxy_ssl_verifyhost: num 249
## $ proxy_ssl_verifypeer: num 248
## $ ssl_verifyhost : num 81
## $ ssl_verifypeer : num 64
## $ ssl_verifystatus : num 232
AH! So, let's just tell {curl} to forget about the peer certs (which are the "bad" ones):
httr::with_config(
config = httr::config(ssl_verifypeer = FALSE),
getƒ()
)
## Response [https://comtrade.un.org/]
## Date: 2020-06-05 01:44
## Status: 200
## Content-Type: text/html
## Size: 64.1 kB
## <!doctype html>
## <html lang="en">
## <head>
## <meta charset="UTF-8"/>
## <title>UN Comtrade | International Trade Statistics Database</title>
## <meta name="DESCRIPTION" content="United Nations Comtrade Database - Internation...
## <meta name="KEYWORDS" content="trade, trade data, imports, exports, world trade,...
## <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
## <!--<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">-->
## <link href="https://comtrade.un.org/css/bootstrap-3.3.7.min.css" rel="stylesheet" ...
## ...
Boom!
The expr
param to httr:::with_config()
can be any function call or a {}
block with {httr} ops in it.