2016-02-22 26 views
0

我一直在玩一点带有HTTR和rcurl并不能设法翻译下面卷曲GET请求为R GET请求:制作中的R

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

特别,我一直有一些麻烦通过授权选项,因为我无法在这两个库中找到等效参数。这可能是一个自定义标题也许?

回答

2

见尝试新的,进一步完善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 
+0

这个库很酷!你有什么经验呢?你总是得到良好的工作卷曲转换? – jgozal

+0

这绝对是我预见会得到大量使用的一个包。这是相当新的,但我觉得很容易弹出我的curl请求,并获得我可以使用的很多httr代码。 – JackStat

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

https://github.com/hrbrmstr/curlconverter

+0

卷曲转换器真的很酷!我明天会试试这个,并会回复你,让你知道它是否奏效! – jgozal

+0

对不起,花了一些时间回到你身边。此请求奏效!尽管JackStat建议的卷曲转换器在R中提出了请求! – jgozal