【发布时间】:2020-05-27 17:46:44
【问题描述】:
我做了一个基本的 https 响应,将 JSON 格式的数据从客户端发送到我的 a2 Web 服务器上名为 /api 的特定端点的 API。由于某种原因,连接被拒绝,我通过 SSH 访问的终端最终没有记录任何内容。
服务器端代码:
const express = require('express');
const app = express();
app.listen(3000,()=>console.log('listening on port 3000'));
app.use(express.static('public'));
app.post('/api',(request,response)=>
{
console.log(request);
});
要向客户端提供的页面:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
console.log("Page started");
const num1=1;
const num2=2;
const data=35;//{num1,num2};
const options =
{
method: 'POST',
headers:
{
"Content-Type": "application/json"
},
body: JSON.stringify(data)
};
fetch(/*'https://goldengates.club:3000/api'*/'https://goldengates.club:3000/api',options);
</script>
</body>
</html>
提供的客户端页面上的错误消息:
Page started
(index):22 POST https://goldengates.club:3000/api net::ERR_CONNECTION_TIMED_OUT
(anonymous) @ (index):22
goldengates.club/:1 Uncaught (in promise) TypeError: Failed to fetch
我知道存在重大安全漏洞,这只是为了熟悉我从未使用过的特定功能。
【问题讨论】:
标签: javascript node.js http backend web-development-server