如何使用doPost(请求)访问应用程序脚本中的发布请求主体 [英] How to access body of post request in app script using doPost(request)
问题描述
我需要在Google App Script中访问发布请求的原始内容。我看到有类似于
$ b $ pre $ 函数doPost(request){
request.contentLength
}
实际上会返回请求正文原始内容的正确长度。所以我认为必须有一些东西来获得完整的身体,例如作为字符串。
我不想访问可能使用post传输的表单字段参数。
从2013年5月9日的发行说明,使用 request.postData.getDataAsString():
函数doPost(request){
var jsonString = request.postData.getDataAsString();
var jsonData = JSON.parse(jsonString);
sheet.appendRow(['Data1:',jsonData.Data1]); //只是一个例子
}
I need to access the raw body of a post request in Google App Script. I see there is something like
function doPost(request) {
request.contentLength
}
that actually returns the right length of the raw content of the request body. So I thought there must be something to get the complete body, e.g. as a String.
I am not looking to access form field parameters that might be transferred using post.
From the Release Notes of May 9, 2013, use request.postData.getDataAsString():
function doPost(request) {
var jsonString = request.postData.getDataAsString();
var jsonData = JSON.parse(jsonString);
sheet.appendRow([ 'Data1:' , jsonData.Data1 ]); // Just an example
}
这篇关于如何使用doPost(请求)访问应用程序脚本中的发布请求主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!