2016-09-29 113 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){/ * ... * /})