【发布时间】:2021-07-30 23:12:29
【问题描述】:
当我从 API 服务器接收数据时,我正在尝试更改 index.html 的元素 h3 index.html的代码
<form action="/" class="" method="POST">
<h1 class=""><span class="clr-dark-purple">VPN</span> & <span class="clr-dark-purple">Proxy</span> Detection.</h1>
<h2>Test to see if an IP address is either a VPN, Proxy, or a TOR node</h2>
<input type="text" name="ip" class="css-input" placeholder="Enter IP Address" required autofocus> <br>
<div class="container-one">
<button type="submit">
Test
<div class="fill-one"></div>
</button>
</div>
<h3></h3>
</form>
app.js 中的代码
app.get("/",function(req,res)
{
res.sendFile(__dirname + "/index.html");
})
app.post("/",function(req,res){
const apikey = "my-api-key";
const ip = req.body.ip;
const url = "https://vpnapi.io/api/" + ip + "?key=" + apikey +"";
console.log(ip, url);
https.get(url,function(response)
{
console.log(response.statusCode);
const chunks = [];
response.on('data', function (chunk) {
chunks.push(chunk)
})
response.on('end', function () {
const data = Buffer.concat(chunks)
var deta = JSON.parse(data)
var vpn = deta.security.vpn;
var proxy = deta.security.proxy;
var city = deta.location.city;
res.write(`<h3><span style="margin-right:1.3em"><span style="color:#301b3f;">VPN:</span> ${vpn}</span><span style="margin-right:1.3em;"><span style="color:#301b3f;">Proxy:</span> ${proxy}</span> <span><span style="color:#301b3f;">City:</span> ${city}</span></h3>
`);
console.log(vpn,proxy,city);
})
})
});
我无法更改 h3 的内容,求助! 其他一切工作正常。谢谢。
【问题讨论】:
标签: javascript node.js api express https