Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlFetchApp unable to access localhost resource

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?

like image 458
Rx2000 Avatar asked Oct 26 '25 21:10

Rx2000


2 Answers

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.

like image 173
Zig Mandel Avatar answered Oct 29 '25 15:10

Zig Mandel


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.

like image 37
Arihant Bengani Avatar answered Oct 29 '25 15:10

Arihant Bengani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!