我需要在Google App脚本中访问发布请求的原始正文。我看到有类似的东西
function doPost(request) {
request.contentLength
}
实际返回请求主体原始内容的正确长度。所以我认为必须要有一些东西来获得完整的 body ,例如作为字符串。
我不希望访问可能使用post传输的表单字段参数。
最佳答案
在Release Notes of May 9, 2013中,使用 request.postData.getDataAsString():
function doPost(request) {
var jsonString = request.postData.getDataAsString();
var jsonData = JSON.parse(jsonString);
sheet.appendRow([ 'Data1:' , jsonData.Data1 ]); // Just an example
}
关于google-apps-script - 如何使用doPost(request)在应用程序脚本中访问发布请求的正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12956354/