UrlFetchApp无法访问本地主机资源 [英] UrlFetchApp unable to access localhost resource
问题描述
这很好:
var resp = UrlFetchApp.fetch("someremotehost/SomeFile.csv");
resp.getResponseCode(); //returns 200
resp.getContentText(); //returns the data
但是,在我的本地计算机上,我正在使用SomeFile.csv运行xampp.csv位于htdocs/dev中,但无法使其在localhost上运行:
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?
推荐答案
该方法无效,因为应用脚本执行了代码服务器端(在Google服务器中).唯一的方法是制作一个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.
这篇关于UrlFetchApp无法访问本地主机资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!