慕運(yùn)維8079593
2023-09-07 16:50:45
我想從我在郵遞員收集工具正文中輸入的 req.body.url 中獲取數(shù)據(jù),如何獲取響應(yīng)我有一個(gè)鍵作為 URL,值作為實(shí)時(shí) URL,請(qǐng)參見下面的屏幕截圖const options = { url: req.body.url, method: 'post', headers: { 'Accept': 'application/json', 'Accept-Charset': 'utf-8', 'User-Agent': 'my-reddit-client' } }; request(options, function(err, res, body) { let json = JSON.parse(options); res.send(json); console.log(json); });嘗試了上面的代碼,但它確實(shí)讀取了 URL 并且不提供數(shù)據(jù)作為響應(yīng)
1 回答

忽然笑
TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
用這個(gè) :
var request = require('request');
const options = {
url: req.body.url,
method: 'post',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8',
'User-Agent': 'my-reddit-client'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
請(qǐng)注意,請(qǐng)求是異步的
添加回答
舉報(bào)
0/150
提交
取消