Node.js 的 Express 是否有 .request()
我正在尝试使用以下代码从外部网址获取响应,但我没有运气。有人可以阐明我做错了什么,并给出他们认为可能有帮助的任何指示。
var express = require('express'),
require('events');
var app = express.createServer();
app.request({
host: "http://ws.audioscrobbler.com",
port: 80,
method: "GET",
path: "/2.0/?method=artist.getsimilar&artist=bandname&api_key=b25b959554ed76058ac220b7b2e0a026"
}).on('response',function(response) {
console.log(response);
});
app.listen(4000);
I'm trying to get a response from an outside url using the below code, but im having no luck. Can someone shed some light on what I'm doing wrong and give any pointers they think could be helpful.
var express = require('express'),
require('events');
var app = express.createServer();
app.request({
host: "http://ws.audioscrobbler.com",
port: 80,
method: "GET",
path: "/2.0/?method=artist.getsimilar&artist=bandname&api_key=b25b959554ed76058ac220b7b2e0a026"
}).on('response',function(response) {
console.log(response);
});
app.listen(4000);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你是否可以。您可以只使用内置的请求功能(请参阅这个:
来自网站:
这非常简单,您仍然可以在现有代码中使用它...
有时框架没有针对所有问题的解决方案...文档是您的朋友。
I don't know if you can. You could just use the built-in request function (see this:
From the website:
It's pretty easy and you can still use it in your existing code...
Sometimes frameworks don't have solutions for everything... the documentation is your friend.