小编Vip*_*nha的帖子

res.write 无法正常工作。它显示包含 HTML 标签的输出

我正在使用 API 和 Express 制作一个简单的 Web 应用程序。\n但我得到的输出与预期不同。我的输出包含包含HTML标签的文本。

\n\n

这是我的代码。

\n\n
const express = require(\'express\');\nconst https = require(\'https\');\nconst app = express();\n\napp.get(\'/\', function(req, res) {\n  const url =\n    \'https://api.openweathermap.org/data/2.5/weather?q=London,uk&units=metric&appid=0333cb6bfed722ca09f1062ec1ea9ca1\';\n  https.get(url, function(response) {\n    console.log(response.statusCode + \' OK\');\n    response.on(\'data\', function(data) {\n      const weatherData = JSON.parse(data);\n      const temp = weatherData.main.temp;\n      const desc = weatherData.weather[0].description;\n      const icon = weatherData.weather[0].icon;\n      const imageURL = \'http://openweathermap.org/img/wn/\' + icon + \'@2x.png\';\n\n      res.write(\'<h3>The weather is currently \' + desc + \'</h3>\');\n      //res.write(\'<img src=\' + imageURL + \'>\');\n      res.write(\n        \'<h1>The …
Run Code Online (Sandbox Code Playgroud)

html javascript httpwebresponse node.js express

3
推荐指数
1
解决办法
5309
查看次数

标签 统计

express ×1

html ×1

httpwebresponse ×1

javascript ×1

node.js ×1