【问题标题】:Adding Recaptcha Token to Request in Nodejs在 Nodejs 中将 Recaptcha 令牌添加到请求
【发布时间】:2018-07-19 17:57:00
【问题描述】:

所以我正在使用 Node.JS 请求模块,我希望将 recaptcha 令牌(一旦解决就会生成)放入我的请求中,但我不确定我是如何实现的。

这是我目前的代码,虽然我尝试了一个表单,但还是不行。

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!");
        }
    })
}

谢谢!

【问题讨论】:

    标签: node.js http-post token recaptcha


    【解决方案1】:

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

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

    按照Request文档如何发送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

    【讨论】:

    • 实施后奇怪,好像还没有解决验证码问题。
    • 验证码在定义的时间内有效
    • 那是多长时间?对不起
    • 有多个规则要声明是否有效en.wikipedia.org/wiki/CAPTCHA
    • 哦,该死的,最好的方法是什么?我有来自服务的令牌,它只是通过上面的请求放入它可以工作的地方..
    猜你喜欢
    • 1970-01-01
    • 2016-09-19
    • 2019-05-29
    • 1970-01-01
    • 2016-03-17
    • 2020-04-19
    • 2019-10-01
    • 1970-01-01
    • 2019-03-23
    相关资源
    最近更新 更多