如何在R httr函数中的curl命令中写入-d参数?

时间:2018-09-07 20:56:12

标签: r curl httr

我有此curl代码可用于访问某些API,并且工作正常。

curl -X POST https://di-api.drillinginfo.com/v2/direct-access/tokens -H "authorization: Basic MTM1NjMtZGlyZW..bla bla...YmMzNzYyYzQ==" -H "cache-control: no-cache" -H "content-type: application/x-www-form-urlencoded" -H "x-api-key: <<I've used my key>>" -d "grant_type=client_credentials"

我一直在尝试使用httr包在R中完成此操作,但除了状态码404之外,无法获得响应。这就是我正在使用的

library(httr)
di_key <- "c0dad52a932e3268e32234122e759f78"
url <- (paste("https://di-api.drillinginfo.com/v2/direct-access/tokens"))
#url <- gsub(" ", "", url, fixed = TRUE)
req <- POST(url, add_headers("X-API-KEY" = di_key, "Content-Type" = "application/x-www-form-urlencoded", "Authorization" = "Basic MTM1NjMtZGlyZWN0LWFjY2VzczowMjU5M2VlNS1mY2RlLTQwY2ItODE1Yy1kZGU2YmMzNzYyYzQ==", "cache-control" = "no-cache" ), body = list("grant_type" = "client_credentials")) #a request object
json <- content(req, as = "text", encoding = "UTF-8")

我的主要疑问是关于curl命令中的-d,是否我当前是否已在R代码httr函数中翻译过它。如果那很好,那么我现在很头绪如何尝试调试它。任何帮助表示赞赏,谢谢!

0 个答案:

没有答案