我不知道我的服务器和代码出了什么问题。我正在通过教程,并且像视频中一样做了所有的事情,但仍然有问题
发布于 2020-04-02 19:04:59
您似乎正在使用https连接,而没有处理TLS证书的传递。
下面是一段代码片段,使您无需配置证书即可访问openweathermap API。
const express = require('express')
const https = require('https')
const app = express()
app.get("/", function(req, res) {
const url = "<openweathermap>"
var options = require('url').parse( /**String*/ url );
options.rejectUnauthorized = false;
https.get(options, function(response) {
console.log(response);
}).on( 'error',function ( e ) {
console.log(err);
}).end();
res.send("Sever up and running");
}
app.listen(3000, function(){
console.log("Server running on port 3000";
}我建议阅读有关如何在Node.JS中为HTTPS设置证书的更多信息,请参阅此doc.以获取更多详细信息。
https://stackoverflow.com/questions/60989792
复制相似问题