Rx2000
Rx2000

Reputation: 41

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?

Upvotes: 4

Views: 6928

Answers (2)

Arihant Bengani
Arihant Bengani

Reputation: 47

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.

Upvotes: 1

Zig Mandel
Zig Mandel

Reputation: 19835

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.

Upvotes: 6

Related Questions