http_post | R Documentation |
Start an HTTP POST request in the background, and report its completion via a deferred value.
http_post(
url,
data = NULL,
data_file = NULL,
data_form = NULL,
headers = character(),
file = NULL,
options = list(),
on_progress = NULL
)
url |
URL to connect to. |
data |
Data to send. Either a raw vector, or a character string
that will be converted to raw with base::charToRaw. At most one of
|
data_file |
Data file to send. At most one of |
data_form |
Form data to send. A name list, where each element
is created with either |
headers |
HTTP headers to send. |
file |
If not |
options |
Options to set on the handle. Passed to
|
on_progress |
Progress handler function. It is only used if the
response body is written to a file. See details at |
An async HTTP deferred object is also an event emitter, see
http_get()
for details, and also event_emitter.
json <- jsonlite::toJSON(list(baz = 100, foo = "bar"))
do <- function() {
headers <- c("content-type" = "application/json")
http_post("https://eu.httpbin.org/post", data = json, headers = headers)$
then(http_stop_for_status)$
then(function(x) {
jsonlite::fromJSON(rawToChar(x$content))$json
})
}
synchronise(do())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.