【问题标题】:Coffeescript HTTP clientCoffeescript HTTP 客户端
【发布时间】:2013-09-13 15:46:48
【问题描述】:

我正在从这个页面运行server.coffeehttps://github.com/xenph/foaas

从命令行,你可以:

curl http://localhost:5000/off/Name1/Name2
!@#$ off, Name1. - Name2

但我正在使用此页面中的代码:http://coffeescriptcookbook.com/chapters/networking/basic-http-client

http = require 'http'

http.get { host: 'http://localhost:5000/off/Name1/Name2' }, (res) ->
    data = ''
    res.on 'data', (chunk) ->
        data += chunk.toString()
    res.on 'end', () ->
        console.log data

我得到的错误是:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: getaddrinfo ENOTFOUND
  at errnoException (dns.js:37:11)
  at Object.onanswer [as oncomplete] (dns.js:124:16)

这让我相信它没有找到网址。

我能做什么?

【问题讨论】:

    标签: node.js http coffeescript


    【解决方案1】:

    试试

    http.get 'http://localhost:5000/off/Name1/Name2', (res) ->
    

    http.get { hostname: 'localhost', port: 5000, path: '/off/Name1/Name2' }, (res) ->
    

    而不是

    http.get { host: 'http://localhost:5000/off/Name1/Name2' }, (res) ->
    

    也许?

    【讨论】:

      【解决方案2】:

      首先从异常中提取更多信息:

      .on('error',function(e){
         console.log("Error: " + hostNames[i] + "\n" + e.message); 
         console.log( e.stack );
      });
      

      其次,当 curl 工作时,我们可以假设该服务已启动并可从 localhost 访问,因此肯定存在更深层次的问题。你用的是什么风格的linux?我之前通过禁用防火墙(iptables)和selinux解决了类似的问题。

      还要仔细检查以确保您已配置 dns 并且它将为 localhost 返回 127.0.0.1。使用 nslookup。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-28
        • 1970-01-01
        • 1970-01-01
        • 2018-10-01
        • 2021-12-05
        • 2019-04-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多