最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - UrlFetchApp DNS error - Stack Overflow

programmeradmin1浏览0评论

I am writing a javascript in the Google spreadsheets and trying to fetch a URL. When i run curl on the same URL I am able to get it working. But when i try to use UrlFetchApp from javascript I get DNS error. Below is my code sample . Am I missing something ?

function upload() {
    Logger.log("hello, ");
    var headers = {
       'Content-Length' : 0
    };
    var options = {
        'method': 'post',
        'useIntranet': true,
        'validateHttpsCertificates': false,
         'contentType': 'text/xml'
     };
   var response = UrlFetchApp.fetch("http://localhost:8787/test/v2/feed", options);
   Logger.log("fetched data");
   Logger.log(response);
 }

I am writing a javascript in the Google spreadsheets and trying to fetch a URL. When i run curl on the same URL I am able to get it working. But when i try to use UrlFetchApp from javascript I get DNS error. Below is my code sample . Am I missing something ?

function upload() {
    Logger.log("hello, ");
    var headers = {
       'Content-Length' : 0
    };
    var options = {
        'method': 'post',
        'useIntranet': true,
        'validateHttpsCertificates': false,
         'contentType': 'text/xml'
     };
   var response = UrlFetchApp.fetch("http://localhost:8787/test/v2/feed", options);
   Logger.log("fetched data");
   Logger.log(response);
 }
Share Improve this question edited Mar 9 at 18:31 Wicket 38.5k9 gold badges78 silver badges193 bronze badges asked Jan 13, 2015 at 5:43 Muppa DivyaMuppa Divya 532 silver badges8 bronze badges 5
  • The GET method also throws error? Your sending a POST with XML but with no payload. – Kriggs Commented Jan 13, 2015 at 11:34
  • I tried adding 'payload' : 'feed:testData' to the options and still i get the same error. – Muppa Divya Commented Jan 13, 2015 at 18:07
  • I also tried using GET instead of POST. I still get the DNS error. – Muppa Divya Commented Jan 13, 2015 at 18:17
  • When I change 'useIntranet' : false, then I don't get DNS error but there is no result as well. The response is empty. I don't think the request is even making the API call in this case. – Muppa Divya Commented Jan 13, 2015 at 18:18
  • stackoverflow./questions/30085768/urlfetchapp-woes – Virako Commented Jan 12, 2016 at 0:22
Add a ment  | 

1 Answer 1

Reset to default 7

This can't work. The UrlFetchApp is executing from a Google server, which isn't on the same network as your machine, so when it tries to find your server running on localhost it can't find it.

发布评论

评论列表(0)

  1. 暂无评论