2

我想将以下 curl 调用移至 Rcurl:

curl  'http://myserver.org/stream' 
-H 'Authorization: Basic XXXXXXXX' -H 'Connection: keep-alive' --data-binary '{"limit": 20}' 
-H 'Content-Type: application/json;charset=UTF-8'

这是我的 R 测试之一:

library(RCurl)
url.opts <- list(httpheader = list(Authorization ="Basic XXXXXXXX", 
                Connection = "keep-alive", 
                "Content-Type" = "application/json;charset=UTF-8"))

getURLContent('http://myserver.org/stream', .opts=url.opts)

现在我缺少添加--data 或--data-binary 的属性。如何添加此选项?

非常感谢马库斯

4

1 回答 1

4

非常感谢@hadley。

这是我的工作解决方案:

library(httr)
user <- "test"
password <- "test123"
POST(url = 'http://myserver.org/stream', 
     config = c(authenticate(user, password, "basic"), 
                add_headers(Connection = "keep-alive"), 
                accept_json()), 
     body = "{'username':'test'}")
于 2013-08-29T13:03:04.320 回答