本文介绍了UrlFetchApp DNS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google电子表格中写入一个JavaScript,并试图获取一个URL。当我在相同的URL上运行curl时,我能够使其工作。但是,当我尝试从JavaScript使用UrlFetchApp时,我得到DNS错误。以下是我的代码示例。我错过了什么吗?

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);
 }


推荐答案

这是行不通的。 UrlFetchApp正在从一台谷歌服务器上执行,它与您的机器不在同一网络上,所以当它试图找到在本地主机上运行的服务器时,它找不到它。

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.

这篇关于UrlFetchApp DNS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 20:34