400 错误

问题描述 投票:0回答:1

我创建并公开了这个非常简单的 Google Apps 脚本:

function doPost(e) {
  try {
    Logger.log('Data received : ' + JSON.stringify(e));
        return ContentService.createTextOutput(JSON.stringify({status: 'success'})).setMimeType(ContentService.MimeType.JSON);
  } catch (error) {
    Logger.log('Error: ' + error.message);
    return ContentService.createTextOutput(JSON.stringify({status: 'error', message: error.message})).setMimeType(ContentService.MimeType.JSON);
  }
}

function doGet(e) {
  return ContentService.createTextOutput("Only POST request accepted.");

使用这些设置: 以我的身份执行,每个人都可以访问。

但是当我尝试从 WordPress 调用它时,它失败并出现 400 错误。

我可以在 GAS 编辑器的执行历史记录中看到调用,但根本没有日志。

这是这个curl命令的结果:

curl -L -X POST https://script.google.com/macros/s/AKfycbxxb17haq53hMcRnfPIwIz9vNamPar4qXYKEmToq2gOTpw9iHRIrc7DnTXgg7c45PS3/exec \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "progression": 50, "id_formation": "formation123"}'
页面 introuvable.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog -inline-block{显示:内联}#drive-logo{边距:18px 0;位置:绝对;空白:nowrap}.docs-drivelogo-img{背景图像:url(//ssl.gstatic.com/图片/branding/googlelogo/1x/googlelogo_color_116x41dp.png);-webkit-background-size:116px 41px;background-size:116px 41px;display:inline-block;height:41px;vertical-align:bottom;width:116px} .docs-drivelogo-text{颜色:#000;显示:内联块;不透明度:.54;文本装饰:无;字体系列:“Product Sans”,Arial,Helvetica,sans-serif;字体大小: 32px;文本渲染:optimizeLegibility;位置:相对;顶部:-6px;左侧:-7px;-webkit-font-smoothing:抗锯齿;-moz-osx-font-smoothing:灰度}@media (-webkit-min-设备像素比:1.5),(最小分辨率:144dpi){.docs-drivelogo-img{背景图像:url(//ssl.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_116x41dp.png) }}哨兵{}主体{背景颜色:#fff;字体系列:Arial、无衬线字体;字体大小:13px;保证金:0;填充:0;}a,a:链接,a:访问过{颜色:#112ABB;}.errorMessage {字体大小:12pt;字体粗细:粗体; line-height: 150%;} DriveImpossible d'ouvrir le fichier pour le moment.

验证地址,快速阅读。

在 Google Drive 上实现最大效率

Google Drive 应用程序简化创建、存储将文档、计算结果、演示文稿和再来一次分开。

倒入更多信息,请参阅页面 drive.google.com/start/apps

html {高度:100%;溢出:自动;}主体{高度:100%;溢出:自动;}#outerContainer {边距:自动;最大宽度:750px;}#innerContainer {margin-bottom:20px;左边距:40px;右边距:40px;顶部边距:80px;位置:相对;}%
google-apps-script web-applications google-workspace http-status-code-400
1个回答
0
投票

在您显示的curl命令和

With these settings: Execute as me and everyone can access.
中,请修改如下并再次测试。

修改curl命令:

curl -L https://script.google.com/macros/s/AKfycbxxb17haq53hMcRnfPIwIz9vNamPar4qXYKEmToq2gOTpw9iHRIrc7DnTXgg7c45PS3/exec \
-d '{"email": "[email protected]", "progression": 50, "id_formation": "formation123"}'

关于

I can see the call in the executions historic from GAS editor but with no logs at all.
,在这种情况下,此信息可能有用。 参考(作者:我)

注:

  • 我猜想在您显示的curl命令中,Google Apps脚本可以工作。但是,没有返回正确的响应。在这种情况下,这篇文章可能会有用。 参考(作者:我)

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.