Home > Enterprise >  Determine if a link is http of https from a string that does not contain the full url
Determine if a link is http of https from a string that does not contain the full url

Time:02-06

I have an input string that contains a partial URL such as "wikipedia.org" and I want to get the full URL "https://www.wikipedia.org/" using Node or JavaScript. Is there a standard way to do this?

The problem is not knowing if the URL is HTTP or https and I would rather not make two API calls to test each case.

CodePudding user response:

That problem can be solved by calling a specific API that provides SSL Verify checks.

As an example you can use rapidapi.

const axios = require("axios");

const options = {
  method: 'POST',
  url: 'https://ssl-certificate-checker.p.rapidapi.com/ssl-certificate',
  headers: {
    'content-type': 'application/json',
    'X-RapidAPI-Key': '9a02e1bd8emsh83423276ecdc759p153572jsn874d28bed296',
    'X-RapidAPI-Host': 'ssl-certificate-checker.p.rapidapi.com'
  },
  data: '{"port":"443","url":"wikipedia.org"}'
};

axios.request(options).then(function (response) {
    console.log(response.data);
}).catch(function (error) {
    console.error(error);
});

For details you can check the site of the API.

Click here to check articles and solutions to similar questions.

  • Related