admin管理员组文章数量:1312640
I've made an API and every route was working until now. When i try to make a POST request to the route "/scammer" i receive this error message: Error: write EPROTO 1979668328:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record:242:
Postman Console
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const utils = require('./utils');
const app = express();
const port = process.env.PORT || 4000;
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
}).then(db => console.log('DB is connected! '))
.catch(err => console.log(err));
const Users = require('./models/users');
app.use(cors());
app.use(express.json());
const fieldCheck = (field, res) => {
return !field ? (res.status(400).json({
error: true,
message: `Invalid ${field}`
})) : field
}
app.route('/scammer')
.post(async (req, res) => {
const userId = fieldCheck(req.body.user_id, res);
await Users.updateOne({ 'user_id': userId }, { 'scammer': req.body.scammer });
res.json({ 'error': false });
});
app.listen(port, () => {
console.log('Server started on: ' + port);
});
I've made an API and every route was working until now. When i try to make a POST request to the route "/scammer" i receive this error message: Error: write EPROTO 1979668328:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record:242:
Postman Console
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const utils = require('./utils');
const app = express();
const port = process.env.PORT || 4000;
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
}).then(db => console.log('DB is connected! '))
.catch(err => console.log(err));
const Users = require('./models/users');
app.use(cors());
app.use(express.json());
const fieldCheck = (field, res) => {
return !field ? (res.status(400).json({
error: true,
message: `Invalid ${field}`
})) : field
}
app.route('/scammer')
.post(async (req, res) => {
const userId = fieldCheck(req.body.user_id, res);
await Users.updateOne({ 'user_id': userId }, { 'scammer': req.body.scammer });
res.json({ 'error': false });
});
app.listen(port, () => {
console.log('Server started on: ' + port);
});
Share
Improve this question
asked Jun 30, 2020 at 18:31
chillin.killerchillin.killer
1282 silver badges13 bronze badges
1
- Hi, please check with http weather it's working or not. It seems you are having some issues with your open ssl certificate. – Shivanshu Gupta Commented Jun 30, 2020 at 18:33
1 Answer
Reset to default 7routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record:242:
It seams that you used HTTPS insted of HTTP to POST to your API
本文标签: javascriptError when making POST requests with ExpressStack Overflow
版权声明:本文标题:javascript - Error when making POST requests with Express - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741919277a2404913.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论