使用FastRWeb捕获HTTP POST内容? [英] Capturing HTTP POST contents with FastRWeb?

查看:68
本文介绍了使用FastRWeb捕获HTTP POST内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用FastRWeb捕获POST变量(或HTTP请求的其他部分)吗? FastRWeb是使您能够在cgi环境中运行r脚本的工具.这是使用FastRWeb的示例程序.

Is anyone aware of how to capture POST variables (or other parts of the HTTP request) using FastRWeb? FastRWeb is a tool which enables 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()
}

"n"参数将从url查询参数捕获到URL.我也想捕获POST内容.有人知道该怎么做吗?

The "n" argument will be captured from the url query parameters to the URL. I would like to capture POST contents as well. Does anyone know how to do this?

干杯.

推荐答案

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

I figured this out! The lead I needed was to read the NEWS file in my FastRWeb distribution. Here is an example script which echoes back the POST contents (if these contents exist).

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

I get that this is quite simple but it doesn't seem to be documented anywhere besides the NEWS file...

这篇关于使用FastRWeb捕获HTTP POST内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆