我想翻译以下 HTTP GET 命令以与 RCurl 一起使用:
curl -G https://api.example.com/resource \
-d "param=value" \
-d "param=value" \
-u 'user:password'
这是我在 RCurl 中使用 getURL 的尝试:
getURL("https://api.example.com/resource",
userpwd ="username:password",param="value",param="value")
第一个代码块在我的命令行终端中工作正常,并且在我尝试设置参数之前使用 getURL 没有遇到任何问题;我收到警告消息,指出参数是“无法识别的 CURL 选项”。有什么想法吗?
最佳答案
任何进入 ...
参数的内容都被解释为curl 选项。您需要将参数作为列表放入 httpheader
参数中。 See documentation .
尝试如下:
getURL("https://api.example.com/resource",
userpwd ="username:password",
httpheader=list(param1="value",param2="value"))
关于r - 使用 RCurl 中的 getURL 将查询参数设置为 RESTful API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19172624/