UrlFetchApp unable to access localhost resource

梦想的初衷 提交于 2019-11-27 08:23:48

问题


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:


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.




回答2:


Use Proxy. I had the same issue, where my app was on AWS ec2.

For that, I used nginx as proxy server and it worked.



来源:https://stackoverflow.com/questions/30085768/urlfetchapp-unable-to-access-localhost-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!