如何使用RCurl包发出以下请求?
curl -X GET "https://api.youneedabudget.com/v1/budgets/XXXXX/accounts" \
-H "accept: application/json" -H "Authorization: Bearer XXXXX"
答案 0 :(得分:0)
您是否必须使用RCurl
软件包?这是使用curl
软件包的解决方案:
library(curl)
h <- new_handle()
handle_setheaders(h,
"accept" = "application/json",
"Authorization" = "Bearer XXXXX"
)
req <- curl_fetch_memory("http://httpbin.org/get", handle = h)
jsonlite::prettify(rawToChar(req$content))
#> {
#> "args": {
#>
#> },
#> "headers": {
#> "Accept": "application/json",
#> "Accept-Encoding": "gzip, deflate",
#> "Authorization": "Bearer XXXXX",
#> "Connection": "close",
#> "Host": "httpbin.org",
#> "User-Agent": "R (3.5.0 x86_64-pc-linux-gnu x86_64 linux-gnu)"
#> },
#> "origin": "77.180.186.114",
#> "url": "http://httpbin.org/get"
#> }