Sunday 19 March 2017

What is correct format of Node.js http.request options hostname parameter?

I am trying to make a request to an Instagram API, I have troubles to understand why http.request hostname parameter from options.

Yet here is my code:

const http = require("http");
const https = require("https");

function requestInstagramData(){
    var options = {
      protocol: "https:",
      hostname: "https://api.instagram.com",
      path: "/v1/tags/fashion?access_token=3681332213.81b69f2.88020902f003411196c3f4423912f547",
      method: "GET"
    };
    var instaRequest = https.request(options);

     instaRequest.on("response", function(res){
      res.on("data", function(data){
        console.log("data has arrived");
      });

      console.log("response");
      console.log(res.statusCode);
      console.log(res.statusMessage);
    });

    instaRequest.end();

}
requestInstagramData();

This code doesnt work, but if I change hostname in options object to

hostname: "api.instagram.com"

It is working.

Why?



via margarita

No comments:

Post a Comment