Reputation: 41
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
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
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