使用RCurl中的getURL将查询参数设置为RESTful API

时间:2013-10-04 03:18:42

标签: r get rcurl

我想将以下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选项”。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

转到...参数的任何内容都被解释为卷曲选项。您需要将参数作为列表放在httpheader参数中。 See documentation

尝试类似:

getURL("https://api.example.com/resource",
       userpwd ="username:password",
       httpheader=list(param1="value",param2="value"))