本文介绍了UrlFetchApp的困扰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这工作正常:

var resp = UrlFetchApp.fetch("someremotehost/SomeFile.csv");
resp.getResponseCode();  //returns 200
resp.getContentText();   //returns the data

然而,在我的本地机器上,我用SomeFile.csv运行xampp位于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 postman和正常工作,为什么UrlFetchApp.fetch()不起作用?

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?

推荐答案

这不会工作,因为apps脚本执行代码服务器端(在谷歌服务器)。做到这一点的唯一方法是制作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的困扰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:12