【发布时间】:2019-02-09 01:10:40
【问题描述】:
模糊地遵循这个“教程”:https://stackabuse.com/the-node-js-request-module/
我收到警报('Options Declared'),但随后我的程序在请求处停止,我不知道为什么。
const request = require('request');
function testGet(){
alert("Get test started");
const options = {
url: "https://www.reddit.com/r/funny.json",
method: 'GET',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8',
'User-Agent': 'my-reddit-client'
}
}
alert("Options declared");
request(options, function(err, res, body){
let json = JSON.parse(body);
console.log(json);
});
alert("Get test done");
}
【问题讨论】:
-
你能在请求中控制台错误吗.. 我的意思是放一个 console.log(err) 并在这里分享
-
它不应按要求停止。它将继续并打印“完成测试”。还有,你是如何执行警报的?你写过自定义方法console.log吗?
标签: javascript node-request get-request