Reputation: 1
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)
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);
});
}
Upvotes: 0
Views: 176
Reputation: 1466
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
Upvotes: 1