UrlFetchApp woes

2019-02-27 12:38发布

This works fine:

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

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!

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?

1条回答
我只想做你的唯一
2楼-- · 2019-02-27 13:19

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.

查看更多
登录 后发表回答