Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在RCurl中使用卷曲选项_R_Rcurl - Fatal编程技术网

如何在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,

如何使用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,
                  "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"
#> }