我一直在犯这个错误。有人知道怎么解决这个问题吗?它执行http请求,但似乎在某个地方遗漏了json.stringify。
应用程序js
let server = http.createServer(function (req, res) {
path = req.url;
if (path === undefined || path === '/') {
res.end('Welcome... all-about-clash site.');
} else {
const options = {
host: 'api.clashofclans.com',
path: path,
url: 'https://api.clashofclans.com' + path,
method: 'GET',
json: true,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
}
};
request(options, (error, response, body) => {
if (!error) {
res.write(JSON.stringify(body));
res.end();
} else {
res.write(JSON.stringify(error));
res.end();
}
});
}
});