2016-09-29 114 views
0

我通过我的服务器在尝试代理/流API调用验证码为T需要秘密通过与后调用,此刻它的那样简单:添加参数请求()流

app.post('/captcha', (req, res) => { 
    const url = 'https://www.google.com/recaptcha/api/siteverify' 
    // Add parameter 'secret' with value config.CAPTCHA_SECRET here 
    req.pipe(request({ url })).pipe(res) 
}) 

注释掉的线是我目前正在挣扎的地方,我需要在调用中添加额外的参数,同时仍然保留已经存在的所有内容。

回答

1

你可以用request.post做到:

req.post(
    'https://www.google.com/recaptcha/api/siteverify', 
    { secret: config.CAPTCHA_SECRET }, 
    function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
      console.log(body) 
     } 
    } 
); 

docs

request.post( 'http://service.com/upload',{形式:{键: '值'}})//或 request.post('http://service.com/upload',form:{key:'value'}}, function(err,'value')。 httpResponse,body){/ * ... * /})