簡體   English   中英

你如何使用RCurl從R中的https中提取數據

[英]how do you pull in data from https in R using RCurl

我正在嘗試使用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中做到這一點?

如果不了解您正在使用的特定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對象(通常是列表)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM