I would like to get the raw text of a POST request's body using the R web server package Rook.
I have registered the R app:
parsePOST <- function(env) {
request <- Rook::Request$new(env)
body <- request$body()
print(body)
}
R.server$add(app = parsePost, name = "reportGeneratorApp")
Unfortunately, body
is a Rook::RhttpdInputStream
. Things I've tried:
This provides only the first line:
body <- request$body()$read_lines()
Result:
{\n
This provides only the start of the body, regardless of the "Content-Length" header. All other read lines are
character(0)
. Additionally, the lines have missing data in random places.
body <- request$body()$read_lines(10)
Results:
[2] " \"data\": {\n "
[3] "evious\": [\n 2\n ],\n \"v"
[4] "e\": {\n \"Differentially private me"
[5] " \"values\": [\n 44.39"
[6] "an mechanismLaplace\"\n ],\n \"arguments\": ["
[7] " },\n \"batch\": [\n 1\n ]\n }\n "
[8] "\n ]\n }\n }\n },\n \"educ_income\": {\n \"ols\": {\n \"ols0\": {\n \"rel"
[9] ""
[10] ""
The POST request is being sent by postman, with the header Content-Type: application/json
.
I'm very surprised to find it so difficult to retrieve the request body.