这很好用:
var resp = UrlFetchApp.fetch("someremotehost/SomeFile.csv");
resp.getResponseCode(); //returns 200
resp.getContentText(); //returns the data
但是,在我的本地机器上,我正在运行xampp,SomeFile.csv位于htdocs / dev中,但是我无法让它在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")
不工作?
这不会起作用,因为应用程序脚本执行代码服务器端(在谷歌服务器中)。执行此操作的唯一方法是创建一个htmlService应用程序并使用前端的ajax。
使用代理服务器。我有同样的问题,我的应用程序在AWS ec2上。
为此,我使用nginx作为代理服务器,它工作。