Coffeescript HTTP客户端 [英] Coffeescript HTTP client

查看:230
本文介绍了Coffeescript HTTP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从此页面运行 server.coffee https ://github.com/xenph/foaas

I am running server.coffee from this page: https://github.com/xenph/foaas

在命令行中,您可以:

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

但我使用的是这个页面的代码: http://coffeescriptcookbook.com/chapters/networking/basic-http-client

But I'm using the code from this page: 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)

这让我相信它找不到url。

Which leads me to believe that it's not finding the url.

我可以做什么?

推荐答案

b

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

也许?

这篇关于Coffeescript HTTP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆