Google Apps Script/Sheet Returns Bad Request 400

旧街凉风 提交于 2019-12-07 06:47:34

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/36742212/google-apps-script-sheet-returns-bad-request-400

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!