0

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);
    });
}

2
  • Can you share the error log for the above lambda function? Commented Oct 29, 2020 at 7:53
  • 1
    https.put? for get? Commented Oct 29, 2020 at 7:54

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I did use GET instead of put but that resulted in an empty console log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.