I'm trying to get opendata from a website in to my own website. I'm using this code (got it from a w3schools example) and tried to combine that with my working code in Excel/VBA. But somehow I can't get it to work on my website... what am I missing in my html/javascript?
HTML: https://codepen.io/1234cb/pen/ZEEqxJK
<body>
<h1>XMLHttpRequest</h1>
<button type="button" onclick="loadDoc()">Request data</button>
<p id="demo"></p>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState > 1) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "https://www.energielabel.nl/api/v1/checkenergylabel", false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
xhttp.setRequestHeader("Connection", "Keep-Alive");
xhttp.send("Postcode=2651ES&HouseNr=109&HouseNrAddition=");
document.getElementById("demo").innerHTML = this.responseText;
}
</script>
</body>
</html>
VBA:
Sub getopendata()
Set ObjHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "https://www.energielabel.nl/api/v1/checkenergylabel"
ObjHTTP.Open "POST", URL, False
ObjHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
ObjHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ObjHTTP.setRequestHeader "Connection", "Keep-Alive"
ObjHTTP.send ("Postcode=2651es&HouseNr=109")
ActiveCell = ObjHTTP.responsetext
Set ObjHTTP = Nothing
Set xmlDoc = Nothing
End Sub