简体   繁体   中英

How to check a website is running over http or https (protocol)

I am making a http call from angular js. I am not sure about the protocol of the target website.So I want to know the protocol(http/https) of the target site. My code looks like this.

var Path12 = "https://ABC.azurewebsites.net/XYZPage/XYZ_FUNCTION";
$http.get(Path12).success(function (data, status, headers, config) {
  var abc = "";
  var pqr = "";
}).error(function (data, status, headers, config) { });

I want to check this ABC.azurewebsites.net is running on http or https.

You can create an anchor link.

var Path12 = "https://ABC.azurewebsites.net/XYZPage/XYZ_FUNCTION";
var link = $document.createElement('a');
link.href = Path12;
console.log(link.protocol) //http:||https:

Checkout: https://gist.github.com/jlong/2428561

Edit: You can also use the URL class.

var link = new URL(Path12)
{href: "https://abc.azurewebsites.net/XYZPage/XYZ_FUNCTION", origin: "https://abc.azurewebsites.net", protocol: "https:", username: "", password: ""…}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM