HTTPS: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Adding in sample with Requests)
Line 342: Line 342:


=={{header|JavaScript}}==
=={{header|JavaScript}}==
=== Modern Browsers ===
<lang JavaScript>
<lang JavaScript>
fetch("https://sourceforge.net")
(function(url,callback){//on some browsers you can check certificate information.
.then(function(response) {
xhr=new XMLHttpRequest();
return response.text();
xhr.open('GET',url,true);
})
xhr.onreadystatechange=function(){if(xhr.readyState==xhr.DONE){callback(xhr)}};
.then(function(content) {
xhr.send();
console.log(content)
})('https://sourceforge.net',function(xhr){console.log(xhr.response)})
})
.catch(function (err){
console.error(err)
});
</lang>

=== Node.js ===
<lang JavaScript>
const https = require('https');

https.get("https://sourceforge.net", (resp) => {
let content = '';

// A chunk of data has been recieved.
resp.on('data', (chunk) => {
content += chunk;
});

// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(content);
});

}).on("error", (err) => {
console.error("Error: " + err.message);
});
</lang>
</lang>