UrlFetchApp 无法访问本地主机资源
这很好用:
var resp = UrlFetchApp.fetch("someremotehost/SomeFile.csv");
resp.getResponseCode(); //returns 200
resp.getContentText(); //returns the data
但是,在我的本地机器上,我正在运行 xampp,其中 SomeFile.csv 位于 htdocs/dev 但我无法让它在本地主机上工作:
however, on my local machine, I'm running xampp with SomeFile.csv is located in htdocs/dev but I cannot get it to work on localhost:
var resp = UrlFetchApp.fetch("localhost/dev/SomeFile.csv");
resp.getResponseCode(); //returns 0.0
resp.getContentText() //returns nothing!
我检查了 chrome-extension 邮递员和 http://localhost/dev/SomeFile.csv
工作正常,那么为什么 UrlFetchApp.fetch("http://localhost/dev/SomeFile.csv")
不起作用?
I checked with chrome-extension postman and http://localhost/dev/SomeFile.csv
works fine, so why does UrlFetchApp.fetch("http://localhost/dev/SomeFile.csv")
not work?
这行不通,因为应用程序脚本在服务器端(在谷歌服务器中)执行代码.唯一的方法是制作一个 htmlService 应用程序并从前端使用 ajax.
That wont work because apps script executes code server side (in google servers). The only way to do this is to make an htmlService app and use ajax from the frontend.