`Why is the https get request not being sent?
V
V
vladislovev2022-04-07 18:15:37
Node.js
vladislovev, 2022-04-07 18:15:37

Why is the https get request not being sent?

const address = '0xd2522633650ac225eb410d92eb15bf82847b0220';

    const options = {
      "method": "GET",
      "hostname": "api.rarible.org",
      "port": null,
      "path": `/v0.1/items/byOwner/?owner=ETHEREUM:${address}`,
      "headers": {
          "Content-Type": "application/json",
      }
      };

      const req = https.request(options, function(res) {
        // @ts-ignore
        if ((res && res.statusCode < 200) || (res && res?.statusCode >= 300)) {
          return reject(new Error('statusCode=' + res.statusCode));
        }
        // cumulate data
       var body = [];
        res.on('data', function (chunk) {
          body.push(chunk);
        });
        // resolve on end
        res.on('end', function () {
          const body1 = Buffer.concat(body)
          try {
            body = JSON.parse(body1.toString('Uint8Array'));
          } catch (e) {
            resolve(body1);
            return
          }
          resolve(body1);
          return
        });
      });
    req.on('error', function (err) {
      reject(err);
    });
    req.end();
  });


Here is the code, strangely, it does not receive a response from the request. Doesn't throw any errors, and doesn't print anything to the console either. Ran it in postman and it works

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question