[英]Post form data with Node.js
如何將輸入表單數據發布為url。 示例代碼如下所示。
app.get('/', (req, res) => {
res.render('index');
});
app.post('/scrape', function(req, res){
const name = req.body.username;
res.send('You sent the name "' + name + '".');
});
app.get('/scrape', function (req, res) {
const name = req.body.username;
res.send('You sent the name "' + name + '".');
url = `http://www.github.com/${name}`;
request(url, function (error, response, html) {
//
//
//
})
res.send('Check your console!')
})
})
所以我想在索引頁面上獲取用戶名並將表單值發布到抓取頁面。
您要發出請求還是發出請求? 如果您嘗試發出獲取請求,則它應以這種方式工作
request("http://www.github.com/whatever", function (error, response,html) {
console.log(response)
})
對於表單數據,請閱讀更多https://github.com/request/request#forms
request.post({url:'http://service.com/upload', formData: formData},
function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.