尽管我有数据请求,我仍尝试使用OMDB API检索数据并始终显示“内部服务器错误”: res.send(results [“ search”] [0])(请注意,我正在使用goorm IDE)
var express = require("express");
var app = express();
var request = require("request");
app.get("/results", function(req, res){
request("http://www.omdbapi.com/?s=california&apikey=thewdb", function(error, response, body){
if(!error && response.statusCode == 200) {
var results = JSON.parse(body);
res.send(results["search"][0]);
}
});
});
app.listen(3000, function(){
console.log("SERVER IS RUNNING");
});
答案 0 :(得分:1)
答案 1 :(得分:0)
可以尝试吗?
app.get("/results", (req, res) => {
request("http://www.omdbapi.com/?s=california&apikey=thewdb", (error, response, body) => {
(!error && response.statusCode == 200) ?
res.send(JSON.parse(body).Search[0])
:
res.send({ err: error });
});
});