/ / Rcurl con dati http post-r, rcurl

Rcurl con dati http post-r, rcurl

Vorrei spostare il seguente ricciolo in 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"

Questo è uno dei miei test 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)

Ora mi manca un attributo per aggiungere --data o --data-binary. Come aggiungere questa opzione?

molte grazie Markus

risposte:

3 per risposta № 1

Grazie mille @hadley.

Questa è la mia soluzione di lavoro:

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"}")