如何在RCurl中使用卷曲选项
如何使用RCurl包发出以下请求如何在RCurl中使用卷曲选项,r,rcurl,R,Rcurl,如何使用RCurl包发出以下请求 curl -X GET "https://api.youneedabudget.com/v1/budgets/XXXXX/accounts" \ -H "accept: application/json" -H "Authorization: Bearer XXXXX" 您必须使用RCurl软件包吗?下面是使用curl包的解决方案: library(curl) h <- new_handle() handle_setheaders(h,
curl -X GET "https://api.youneedabudget.com/v1/budgets/XXXXX/accounts" \
-H "accept: application/json" -H "Authorization: Bearer XXXXX"
您必须使用
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"
#> }
库(curl)
h“args”:{
#>
#> },
#>“标题”:{
#>“接受”:“应用程序/json”,
#>“接受编码”:“gzip,deflate”,
#>“授权”:“持有人XXXXX”,
#>“连接”:“关闭”,
#>“主机”:“httpbin.org”,
#>“用户代理”:“R(3.5.0 x86_64-pc-linux-gnu x86_64 linux gnu)”
#> },
#>“来源”:“77.180.186.114”,
#>“url”:”http://httpbin.org/get"
#> }