Capturing HTTP POST content using FastRWeb?

Does anyone know how to commit POST variables (or other parts of an HTTP request) using FastRWeb? FastRWeb is a tool that allows you to run r scripts in a cgi environment. Here is an example program using FastRWeb.

run <- function(n = 100, ...) {
# direct HTML output
out("<H2>Some HTML</h2>")
# all arguments are passed as strings from the URL, so convert to numeric as needed
n <- as.integer(n)
# create a WebPlot
p <- WebPlot(800, 600)
x <- runif(n)
plot(x, rnorm(n), pch=19, col=2)
# insert the plot in the page
out(p)
# verbatim print
oprint(n)
oprint(summary(x))
# HTML table
otable(data.frame(a=1:5, b=c("a","b","c","d","e")))
# return the whole page
done()
}

The argument "n" will be displayed from the url request parameters in the URL. I would also like to write the contents of the POST. Does anyone know how to do this?

Greetings.

+4
source share
1 answer

I get it! I needed to read the NEWS file in my FastRWeb distribution. Here is an example script that has something in common with POST content (if that content exists).

run <- function() {
    if (is.null(request$body)) {
        "no request!"
    } else {
        rawToChar(request$body,multiple=FALSE)
    } 
}

Here is the relevant text from the NEWS file

1.1-0   (2012-12-15)
    o   The interface to the R process has been enhanced to support
        request body and other methods including POST. A new global
        variable `request' is a list that is populated with various
        entries pertinent to the request:
request$uri - URI of the request (used to be request.URI)
request$method - method type (as string) such as "GET"
request$c.type - content type of the request body
request$c.length - length of the request body (-1 if
                       there is no body)
request$body - raw vector containing the body of the request
request$client.ip - IP address of the client (as string)
request$raw.cookies - raw cookie string
request$path.info - path part beyond the script name

All strings are guaranteed to be "" if not set.
request$body will be NULL if there is no body.

, , , , NEWS...

+3

Source: https://habr.com/ru/post/1530801/


All Articles