我目前正在heroku服务器上编写一个webhook,由于某些原因,我很难获得存储在请求体中的值,因为它似乎总是显示为NULL
。我的app.R脚本看起来像指南中的所有脚本:
#app.R
library(plumber)
library(tidyverse)
port <- Sys.getenv('PORT')
pr <- plumb("plumber.R")
pr$run(
host = '0.0.0.0',
port = as.numeric(port)
)
我的plumber.R文件是这样开始的。
library(plumber)
library(tidyverse)
#* Log some information about the incoming request
#* @filter logger
function(req){
print('LOGGER')
print( req)
cat(as.character(Sys.time()), "-",
req$REQUEST_METHOD, req$PATH_INFO, "-",
req$HTTP_USER_AGENT, "@", req$REMOTE_ADDR, "\n")
plumber::forward()
}
#* @filter bodyExists?
function(req, res){
print( 'BODY FILTER')
print( req$body)
if (is.null(req$body)){
res$status <- 404
return(list(error="Body not found"))
} else {
plumber::forward()
}
}
每次收到请求时,控制台都会显示以下内容:
停下来是因为没有身体。我已经尝试从多个来源发送请求,我知道有一个正文正与请求一起发送,但由于某种原因,当它到达我的api时,管道工没有找到它。我一直在使用https://github.com/virtualstaticvoid/heroku-plumber-app作为模板,我看不出我在做什么与他们不同。
发布于 2021-06-24 08:04:18
应该使用req$postBody
而不是req$body
https://stackoverflow.com/questions/68106609
复制相似问题