AWS Lambda HTTP POST 请求 (Node.js) [英] AWS Lambda HTTP POST Request (Node.js)

查看:49
本文介绍了AWS Lambda HTTP POST 请求 (Node.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 AWS lambda 函数和 nodejs 比较陌生.我正在尝试使用来自此网站的 HTTP POST 请求获取一个国家/地区的 5 个城市的列表:http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry"

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 帖子找到的搜索:

Searches that I found for http post:

https://www.npmjs.com/package/http-post如何在 node.js 中发起 HTTP POST 请求?

推荐答案

尝试以下示例,从 AWS lambda 调用 nodejs 中的 HTTP GET 或 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆