【发布时间】:2013-08-28 16:47:16
【问题描述】:
我想将以下 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 的属性。如何添加这个选项?
非常感谢 马库斯
【问题讨论】:
-
你可以使用
getURLContent(..., customrequest = 'POST', postfields = '{"limit": 20}')或类似的东西。 -
使用
httr可能会更容易一些:POST('http://myserver.org/stream', c(authenticate(u, p, "basic"), accept_json(), body = '{"limit": 20}')