Node.js 调 webservice 有什么好的例子吗?
发布于 10 年前 作者 xuwenfei886 8148 次浏览 最后一次编辑是 8 年前

http 创建 server 的那种感觉不够简单易用。有人用过 request 吗?有没有个好的例子。或是其他类似的插件推荐一下。 另外,我现在的项目只需要我从客户端用 WebSocket 向 client 推送数据,是不是没有什么必要使用 Express。

3 回复

我用过一个是 superagent, 个人觉得不错: http://visionmedia.github.com/superagent/ 没有 HTTP 服务不用 Express 没关系呀

request

https://github.com/mikeal/request

这个用的人多…

当然,tj 大神的也不错…

我也是在npmjs看的排在前面的。我现在准备用request来着,遇到点小麻烦,帮我看一下。我用socket.io 在一个on的事件里去请求数据然后返回到页面上,但是现在他并没有去发请求。 <pre><code>socket.on(“newUser”, function(data){ console.log(“newUser:”+data.id+":"+data.name); participants.push({id:data.id,name:data.name}); console.log("---------------------------------------------->Enter New User."+options.url); request(options, callback); }); var options = { url: ‘https://api.github.com/repos/mikeal/request’, headers: { ‘User-Agent’: ‘request’ } }; function callback(error, response, body) { console.log("-------------------------------------------->D"); if (!error && response.statusCode == 200) { var info = JSON.parse(body); console.log(info.stargazers_count + " Stars"); console.log(info.forks_count + " Forks"); } } </code></pre>

回到顶部