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

查看:499
本文介绍了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 post:

Searches that I found for http post:

https://www.npmjs.com/ package / http-post
如何在node.js中发出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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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