在Nodejs中向Request添加Recaptcha令牌



所以我使用Node.JS请求模块,我希望将repatcha令牌(解决后生成(放入我的请求中,但我不确定如何实现。

这是我目前的代码,虽然我尝试过一个表单,但它仍然不会。

function fireVote(username, captchaKey){
rp({
uri: voteUrl,
method: "POST",
qs: {
"username": username,
"g-recaptcha-response": captchaKey
},
headers: {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
}
}).then(body => {
console.log(body);
if(body.includes("Voted")){
console.log("Done!");
}
})
}

谢谢!

您必须在请求正文中发送值,以内容类型指定的格式。

通常,内容类型为application/x-www-form-urlencoded

根据请求文档如何发送POST请求

https://www.npmjs.com/package/request

function fireVote(username, captchaKey){
request.post({
url:voteUrl, 
form: {
"username": username,
"g-recaptcha-response": captchaKey
}}, 
function(err,httpResponse,body){ 
console.log(body);
})
}

实际上,如果您没有在服务器端验证reCAPTCHA,就没有必要发送令牌。

https://developers.google.com/recaptcha/docs/verify

最新更新