【问题标题】:Capturing HTTP POST contents with FastRWeb?使用 FastRWeb 捕获 HTTP POST 内容?
【发布时间】:2014-03-09 05:35:34
【问题描述】:

有人知道如何使用 FastRWeb 捕获 POST 变量(或 HTTP 请求的其他部分)吗? FastRWeb 是一个工具,可让您在 cgi 环境中运行 r 脚本。这是一个使用 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()
}

“n”参数将从 url 查询参数中捕获到 URL。我也想捕获 POST 内容。有谁知道怎么做?

干杯。

【问题讨论】:

    标签: r rserve


    【解决方案1】:

    我想通了!我需要的线索是阅读我的 FastRWeb 发行版中的 NEWS 文件。这是一个示例脚本,它回显 POST 内容(如果这些内容存在)。

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

    这是来自 NEWS 文件的相关文本

    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 文件之外似乎没有记录在任何地方...

    【讨论】:

      猜你喜欢
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      相关资源
      最近更新 更多