我正在发送用户名、密码和 h-captcha-response 令牌以通过登录表单表达。用户名和密码从表单中很好地发送,没有单引号,h-captcha-response(由 hcaptcha 制定并发送回网络表单并发送)正在发送,带有单引号和 hcaptcha中间件 ( express-hcaptcha ) 看不到任何令牌。中间件的响应是......
Error: bad request - no token provided in body
我正在使用https://github.com/vastus/express-hcaptcha
当我转储 req 时,我看到 h-captcha-response 用单引号括起来。我相信这可能与发送到 express 的表单输入未设置为 application/json 有关,但这是一个猜测,因为我是 node/express 的新手。
req 转储的适用部分在下面,后面是节点/快递信息。有人可以指出我正确的方向吗?非常感谢JW
请求转储(通过 console.log )
————-
<snip>
….
….
body:
{ username: ‘xxxx’,
password: ‘xxxx’,
'h-captcha-response': ‘xxxxxxxxxxxxxx’ },
_body: true,
length: undefined,
….
….
<snip>
js文件的相应部分——————</p>
const http = require('http');
const mysql = require('mysql');
const express = require('express');
const session = require('express-session');
const cors = require('cors');
const hcaptcha = require('express-hcaptcha');
//hcaptcha secret key
const SECRET = “xxxxxx”;
var bodyParser = require('body-parser');
var connection = mysql.createConnection({
…..<snip>
});
const path = require('path');
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.set("view engine","hbs");
app.use(bodyParser.urlencoded({extended : true}));
//create app server
var server = app.listen(3000, "0.0.0.0", function () {
var host = server.address().address
var port = server.address().port
});
app.post('/verify', hcaptcha.middleware.validate(SECRET), (req, res) => {
res.json({message: 'verified!', hcaptcha: req.hcaptcha});
});