2016-02-22 25 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