Google Apps脚本/工作表返回错误请求400 [英] Google Apps Script/Sheet Returns Bad Request 400

查看:160
本文介绍了Google Apps脚本/工作表返回错误请求400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google表单上运行了一个相当简单的脚本。

该脚本接受一个webhook POST,并将webhook的内容作为电子表格中的新行写入。

该脚本的功能与预期相同,并在接收数据时写入新行。 然而,我发送webhook的应用程序由于某种原因收到错误的请求400错误。即使脚本工作,它做了它应该做的。



这是脚本的小提琴我在用着。



如果我手动调用这个函数,我会得到一个200响应:

  var response = UrlFetchApp.fetch(https://script.google.com/macros/s/AKfycbx5ubu78yi5sj2D9z-2m3Wqog604wY1ENwP3pZstnB95Mc5_N3b/exec,options); 

这是登录页面上有一个表格。当您提交表单时,表单数据会通过webhook推送到Google表单。 (单击单击我测试此脚本查看表单,如果提交它,则会看到实际表单。) 解决方案

我遇到同样的问题,经过大量的HTTP请求重新发送之后,我意识到这是因为内容安全策略标头。如果它是由服务器设置的,并且您的原点不符合其规则,那么浏览器将显示错误400.



如果有选项UrlFetchApp来取消这个错误。



我还没找到任何解决方法来解决它。请告诉我,如果你这样做。


I have a fairly simple script running on a Google Sheet.

The script accepts a webhook POST and writes the content of the webhook as a new row in the spreadsheet.

The script does function as expected and it writes a new row when it receives data.

However, the app from where I'm sending the webhook receives back "Bad Request 400" error for some reason. Even though the script worked and it did what it was supposed to do.

This is a fiddle of the script I'm using.

If I call this manually, I do get a 200 response:

var response = UrlFetchApp.fetch("https://script.google.com/macros/s/AKfycbx5ubu78yi5sj2D9z-2m3Wqog604wY1ENwP3pZstnB95Mc5_N3b/exec", options);

This is a landing page with a form on it. When you submit the form, the form data gets pushed through a webhook to a Google Sheet. (Click on "Click Me To Test This Script" to see the form and if submit it, you'll see the actual sheet.)

解决方案

I had the same problem and after a lot of resending of the HTTP request, i realized it was because of Content Security Policy header. If it is set by the server and your origin doesn't satisfy its rules, then the browser will show error 400.

It would be great if there was an option in UrlFetchApp to suppress this error.

I haven't found any solution to fix it. please let me know if you do so.

这篇关于Google Apps脚本/工作表返回错误请求400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆