Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.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
在R中发出GET请求_R_Http_Rcurl_Httr - Fatal编程技术网

在R中发出GET请求

在R中发出GET请求,r,http,rcurl,httr,R,Http,Rcurl,Httr,我一直在使用httr和rcurl,无法将以下curl GET请求转换为R: curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint' 特别是,我在通过授权选项时遇到了一些麻烦,因为我在两个库中都找不到等效的参数。它可能是一个自定义标题,也许 httr::GET('

我一直在使用httr和rcurl,无法将以下curl GET请求转换为R:

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint'
特别是,我在通过授权选项时遇到了一些麻烦,因为我在两个库中都找不到等效的参数。它可能是一个自定义标题,也许

httr::GET('https://this.url.api.com:334/api/endpoint', 
      accept_json(), 
      add_headers('Authorization' = 'Bearer 31232187asdsadh23187'))

另请参见

试用新的进一步改进的curlconverter软件包。它将接受一个curl请求并输出一个httr命令

#devtools::install_github("hrbrmstr/curlconverter")

library(curlconverter)

curlExample <- "curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint'"

resp <- make_req(straighten(curlExample))
resp
#devtools::安装_github(“hrbrmstr/curlconverter”)
库(卷曲转换器)

我同意斯考特的回答。我对curlconverter的维护和官方性不太了解,但为了完成功能,我将再添加几行

getInfoInJson <- httr::GET('https://this.url.api.com:334/api/endpoint', 
      accept_json(), 
      add_headers('Authorization' = 'Bearer 31232187asdsadh23187'))

 #safe the info in a json object 
 jsonInfoImg <- content(getInfoInJson, type="application/json")

getInfoInJson旋度转换器真的很酷!我明天会试试这个,然后会给你回复,让你知道它是否有效!很抱歉,我花了一些时间才回复你。这个请求成功了!尽管JackStat建议的旋度转换器使在R中发出请求变得轻而易举!这个图书馆太酷了!你对此有何经验?你总是能得到很好的旋度转换吗?这绝对是一个我预计会得到大量使用的软件包。这是一个相当新的版本,但我发现插入curl请求并获得一大块可以使用的httr代码非常容易。