javascript - 无法使用 Apps 脚本 (Webhooks) 解析 x-www-form-urlencoded
问题描述
我正在尝试使用 Apps 脚本(作为 Web 应用程序)在 Gsheet 中获取 POST 请求!它适用于 JavaScript body POST 类型,但是当我尝试使用 x-www-form-urlencoded 时出现错误。
function doPost(e) {
//Return if null
if( e == undefined ) {
console.log("no data");
return HtmlService.createHtmlOutput("need data");
}
//Parse the JSON data
var event = JSON.parse(e.postData.contents);
var data = event.data;
//Get the last row without data
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = Math.max(sheet.getLastRow(),1);
sheet.insertRowAfter(lastRow);
//Get current timestamp
var timestamp = new Date();
//Insert the data into the sheet
sheet.getRange(lastRow + 1, 1).setValue(event.bt_signature);
sheet.getRange(lastRow + 1, 2).setValue(data.bt_payload);
SpreadsheetApp.flush();
return HtmlService.createHtmlOutput("post request received");}
谢谢!
解决方案
对于x-www-form-urlencoded
内容,POST
数据存储在事件对象的parameter
和parameters
属性中。请参阅文档。
推荐阅读
- python - 如何在绘图模板中包含“titlefont”属性?
- javascript - 如何将“datetime-local”转换为 Unix 时间并将其与 vanilla Javascript 中的当前日期/时间进行比较?
- android - BottomNavigation 下的 Snackbar
- c# - asp.net core 2.1 SecurityStampValidatorOptions ValidationInterval - 在本地工作,在 IIS 中运行
- python - SQLAlchemy 创建引擎和 pyodbc DSN 错误
- node.js - 松露编译失败
- npm - React Native Web:如何找到兼容的包?
- javascript - 画布形状单击可删除多个形状
- python-3.x - 从 dict 到 pandas 数据框作为行
- pycharm - Pycharm 乒乓球游戏