我正在嘗試制作天氣應用程序,但我收到此錯誤。錯誤enter code hereconst express =require("express");const https=require("https");const bodyParser=require("body-parser");const app=express();app.use(bodyParser.urlencoded({extended: true}));app.get("/",function(req,res){res.sendFile(__dirname+"/index.html");});app.post("/",function(req,res){ const query=req.body.CityName; const api_key="658767b0ae936b022f59a69f44868419" const unit="metric";const url="https://api.openweathermap.org/data/2.5/weather?q="+query+"&appid="+"&units="+unit;https.get(url,function(response){ console.log(response.statusCode); response.on("data",function(data){const weather_data= JSON.parse(data);console.log(weather_data);const temp=weather_data.main.tempconst icon=weather_data.weather[0].iconconst icon_id=" http://openweathermap.org/img/wn/"+icon+"@2x.png"res.write("Temp="+temp);res.write("<img src="+icon_id+">");res.send();})});})API密鑰是有效的,因為我已嘗試使用它(https://api.openweathermap.org/data/2.5/weather?q=Trivandrum&appid=658767b0ae936b022f59a69f44868419&units=metric)
使用打開的天氣圖 api/ 時收到 401 錯誤
茅侃侃
2022-08-27 13:57:37