本文介绍了AWS Lambda HTTP POST请求(Node.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对AWS lambda函数和nodejs相对较新。我正在努力尝试使用来自该网站的HTTP POST请求获取一个国家的5个城市的列表:
I'm relatively new to AWS lambda function and nodejs. I'm working on to try and get the list of 5 cities in a country by using HTTP POST request from this website: "http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry"
我一直在搜索如何在lambda函数中执行HTTP POST请求,但我似乎无法找到它的好解释。
I've been searching about how to do a HTTP POST request in lambda function but I can't seem to find a good explanation for it.
搜索我发现的http post:
Searches that I found for http post:
推荐答案
尝试以下示例,调用HTTP GET来自AWS lambda的nodejs中的POST或POST请求
Try the following sample, invoking HTTP GET or POST request in nodejs from AWS lambda
const options = {
hostname: 'hostname',
port: port number,
path: urlpath,
method: 'method type'
};
const req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
// code to execute
});
res.on('end', () => {
// code to execute
});
});
req.on('error', (e) => {
callback(null, "Error has occured");
});
req.end();
考虑样本
这篇关于AWS Lambda HTTP POST请求(Node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!