UrlFetchApp 无法访问本地主机资源 [英] UrlFetchApp unable to access localhost resource

查看:28
本文介绍了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.

这篇关于UrlFetchApp 无法访问本地主机资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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