r - 管道工找不到请求正文
问题描述
我目前正在 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)
)
我的管道工.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作为模板,我看不出我在做什么与他们不同。
解决方案
应该使用req$postBody
而不是req$body
推荐阅读
- java - 问题是针对 eclipse javaEE 版本的。该项目未构建,因为其构建路径不完整
- python - 当程序从不同的目录运行时,需要知道干净的方式来进行导入工作
- sharepoint-online - Add-PnPApp :请求消息已发送。无法多次发送相同的请求消息
- python - 无法使用 Travic CI 从我的 GitHub 存储库运行我的脚本:导入错误
- java - 谷歌自定义图片搜索返回不良图片
- python - 反向按位运算
- javascript - React 的问题(刚开始学习)
- sql-server - 更改 Spring Batch 控制表锁定策略
- javascript - 如何在 JavaScript 中将嵌入转换为变量?
- excel - 从 n 个工作表到新的 Excel 或工作表的 Excel 行号