简体   繁体   English

HTTP 请求未在 AWS Lambda 中获取数据

[英]HTTP request not getting data in AWS Lambda

When I use I paste this link in a browser or even an IDE in my local environment (Webstorm) I get JSON data but when I try to use this function in Lambda it returns an empty string (so the variable datastring is empty)当我使用我将此链接粘贴到本地环境 (Webstorm) 中的浏览器甚至 IDE 中时,我得到 JSON 数据,但是当我尝试在 Lambda 中使用此函数时,它返回一个空字符串(因此变量数据字符串为空)

 const https = require('https'); exports.handler = function(event,context,callback){ let dataString = ''; const req = https.get("https://www.instagram.com/dev1398/?__a=1", function(res) { res.on('data', chunk => { dataString += chunk; }); res.on('end', () => { // console.log(JSON.parse(dataString)); console.log(dataString) }); }); req.on('error', (e) => { console.error(e); }); }

Use

const req = https.get("https://www.instagram.com/dev1398/?__a=1", function(res) {
       res.on('data', chunk => {
       dataString += chunk;
    });

in place of代替

const req = https.put("https://www.instagram.com/dev1398/?__a=1", function(res) {
    res.on('data', chunk => {
       dataString += chunk;
});

You need to use GET method instead of PUT您需要使用GET方法而不是PUT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM