node.js - 处理多个链式https请求 - 在另一个https请求后调用一个https请求

时间:2018-06-07 04:14:14

标签: javascript node.js request httprequest

在我的node.js应用程序中,我正在尝试调用多个链式https请求。我正在尝试调用第一个https请求,并使用第二个https请求中第一个https请求中提取的数据。

以下是我目前的代码:

	let ticker = '';

	var request = https.get({
		host: "api.intrinio.com",
		path: pathString,
		headers: {
			"Authorization": auth
		}
	}, function(response) {
		var json = "";
		response.on('data', function(chunk) {
			json += chunk;
		});

		response.on('end', function() {
			var jsonData = JSON.parse(json);

			console.log(jsonData);

			ticker = jsonData.data[0].ticker;

			var chat = "The company stock ticker for " + companyName + ' is ' + ticker;

			cloudFnResponse.send(buildChatResponse(chat));
		})
	})

  var stockInfoPathString = '/companies?identifier=' + ticker;	

	var newRequest = https.get({
		host: "api.intrinio.com",
		path: stockInfoPathString,
		headers: {
			"Authorization": auth
		}
	}, function(response) {
		var json = "";
		response.on('data', function(chunk) {
 chunk);
			json += chunk;
		});

		response.on('end', function() {
			var jsonData = JSON.parse(json);


		});
	});

我要做的是我发出第一个https get请求并将数据提取到我在第一个get请求之上声明的“ticker”变量。

然后使用该“ticker”数据构建“stockInfoPathString”并在第二个get请求中使用此“stockInfoPathString”。

我在第一个https get请求完成后调用第二个https get请求。

我该怎么做?

0 个答案:

没有答案
相关问题