Sad*_*tun 5 node.js express node-modules
下面给出 Node.js 代码,我尝试使用 https 作为项目所需但出现错误
类型错误 [ERR_INVALID_PROTOCOL]:不支持协议“http:”。预期为“https:”
const express = require("express");
var https = require("https");
const app = express();
app.get("/", function(req, res) {
const url = "http://api.openweathermap.org/data/2.5/weather?q=Gwalior&appid=4b01458a2b74d57ff37f136f382ac4d5&units=metric";
https.get(url, function(response) {
console.log(response.statusCode)
});
res.send("Server is Up and Running");
})
app.listen(3000, function() {
console.log("Server is running on port 3000.");
})
Run Code Online (Sandbox Code Playgroud)
完整的错误堆栈跟踪:
TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
at new ClientRequest (_http_client.js:151:11)
at request (https.js:316:10)
at Object.get (https.js:320:15)
at C:\Users\Public\Documents\WeatherProject\app.js:12:10
at Layer.handle [as handle_request] (C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\Public\Documents\WeatherProject\node_modules\express\lib\router\index.js:335:12)
Run Code Online (Sandbox Code Playgroud)
但如果我使用 http,即使我尝试使用节点安装 https,它也能正常工作(仍然不起作用)
| 归档时间: |
|
| 查看次数: |
8218 次 |
| 最近记录: |