Error: socket hang up - code ECONNRESET - HTTPS Get


#1

Hello,

I’m trying to make a simple request in url “https://api.cartolafc.globo.com/mercado/status” , so that it returns me a JSON response, and as my notebook (https://runkit.com/joaofelipepego/https-is-broken) occurs an error of “socket hang up

Is there anything I can do?


#2

I’ve made a small example that grabs JSON here: https://runkit.com/tolmasky/econnreset-workaround

I’m not sure why directly using http isn’t working. I’ll take a look.


#3

@tolmasky How to add headers content into request get?

example:

headers = {
‘Accept’: ‘application/json, text/plain, /’,
‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36’,
}

Possible???


#4

The following should work:

const https = require("https");

const options = {
    host: "api.cartolafc.globo.com",
    path: "/mercado/status",
    port: 443,
    headers: {
        "User-Agent":  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
    }
}

https.get(options, (r) => {
    //console.log(r);
    r.on("data", function(chunk) {
        console.log("BODY: " + chunk);
    });
});

https://runkit.com/pieter/59bad6a0d5cdfb0012279183