我正在尝试使用RCurl对https网站进行休息调用并下拉这样的数据:
library("httr")
library("XML")
library(RCurl)
setInternet2()
url<-c("https://dynatrace.com:8021/rest/management/reports/create/host_cpu_report?type=XML&format=XML+Export")
getURL(url, cainfo = "R/win-library/3.2/RCurl/dt.cer")
我收到此错误:
Error in function (type, msg, asError = TRUE) :
error setting certificate verify locations:
CAfile: R/win-library/3.2/RCurl/dt.cer
CApath: none
我在RCurl中启用了https,如下所示:
curlVersion()$protocol
[1] "dict" "file" "ftp" "ftps" "gopher" "http" "https" "imap" "imaps" "ldap" "pop3" "pop3s" "rtmp" "rtsp"
[15] "scp" "sftp" "smtp" "smtps" "telnet" "tftp"
任何想法如何在R中做到这一点?
答案 0 :(得分:0)
在不了解您正在使用的特定REST API或您想要进行何种调用的情况下,示例代码段可能如下所示:
library(httr)
GET(content(
url = "https://dynatrace.com:8021/rest/management/reports/create/host_cpu_report",
add_headers(
format = "XML+Export",
type = "XML",
token = "some access token"),
body = "rockin'"
));
使用add_headers()
函数添加参数和值,指定URL(可能)将某种访问令牌和/或正文附加到请求中。 content()
将响应转换为R对象(通常是列表)。