如何获取Google Apps脚本doPost()来读取我的POST请求?

我正在使用node.js和Puppeteer从无头浏览器运行一个抓取项目。我想将数据发布到Google Apps脚本进行进一步处理。我希望在GAS项目中看到带有填充参数的数据。但是,我得到的结果只有空参数。

https://script.googleusercontent.com/macros/echo?user_content_key=[key]
  

{“ parameter”:{},“ contextPath”:“”,“ contentLength”:-1,“ queryString”:“”,“ parameters”:{}}

这是生成该响应的GAS代码。

代码
function doGet(e){
  return handleResponse(e);
}

function doPost(e){
  return handleResponse(e);
}

function handleResponse(e) {
  var json = JSON.stringify(e)
  var textOutput = ContentService.createTextOutput(json);
  return textOutput
}

这是我用来发送请求的代码。

scraper.js
const request = require('request');
request({
  method: POST,preambleCRLF: true,postambleCRLF: true,uri: postUrl,multipart: {
    chunked: false,data,},

我已使用[RequestBin] [1]验证我正在发送有效的POST请求。

我在做什么错了?

lx463419 回答:如何获取Google Apps脚本doPost()来读取我的POST请求?

请检查您如何publishing使用网络应用。

  • 以以下身份执行该应用程序:我
  • 有权访问该应用的人:所有人,甚至是匿名人

POST和GET的URL应该类似于https://script.google.com/macros/s/IDENTIFIER/exec,而不是https://script.googleusercontent.com/macros/echo?user_content_key=[key]。后一个URL看起来像是从发布“任何人,甚至匿名”都无法访问的Web应用程序的重定向。

如果设置正确,则此请求

curl --request POST \
  --url 'https://script.google.com/macros/s/IDENTIFIER/exec?param1=1&param2=2' \
  --header 'content-type: application/json' \
  --data '{"json": true}'

返回

{
  "parameter": {
    "param1": "1","param2": "2"
  },"contextPath": "","contentLength": 14,"queryString": "param1=1&param2=2","parameters": {
    "param1": [
      "1"
    ],"param2": [
      "2"
    ]
  },"postData": {
    "type": "application/json","length": 14,"contents": "{\"json\": true}","name": "postData"
  }
}
本文链接:https://www.f2er.com/3106132.html

大家都在问